tor-browser

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

test_transformFields.js (23287B)


      1 /**
      2 * Tests the transform algorithm in profileStorage.
      3 */
      4 
      5 "use strict";
      6 
      7 let FormAutofillStorage;
      8 add_setup(async () => {
      9  ({ FormAutofillStorage } = ChromeUtils.importESModule(
     10    "resource://autofill/FormAutofillStorage.sys.mjs"
     11  ));
     12 });
     13 
     14 const TEST_STORE_FILE_NAME = "test-profile.json";
     15 
     16 const ADDRESS_COMPUTE_TESTCASES = [
     17  // Name
     18  {
     19    description: "Has split names",
     20    address: {
     21      "given-name": "Timothy",
     22      "additional-name": "John",
     23      "family-name": "Berners-Lee",
     24    },
     25    expectedResult: {
     26      "given-name": "Timothy",
     27      "additional-name": "John",
     28      "family-name": "Berners-Lee",
     29      name: "Timothy John Berners-Lee",
     30    },
     31  },
     32  {
     33    description: "Has split CJK names",
     34    address: {
     35      "given-name": "德明",
     36      "family-name": "孫",
     37    },
     38    expectedResult: {
     39      "given-name": "德明",
     40      "family-name": "孫",
     41      name: "孫德明",
     42    },
     43  },
     44 
     45  // Address
     46  {
     47    description: '"street-address" with single line',
     48    address: {
     49      "street-address": "single line",
     50    },
     51    expectedResult: {
     52      "street-address": "single line",
     53      "address-line1": "single line",
     54    },
     55  },
     56  {
     57    description: '"street-address" with multiple lines',
     58    address: {
     59      "street-address": "line1\nline2\nline3",
     60    },
     61    expectedResult: {
     62      "street-address": "line1\nline2\nline3",
     63      "address-line1": "line1",
     64      "address-line2": "line2",
     65      "address-line3": "line3",
     66    },
     67  },
     68  {
     69    description: '"street-address" with multiple lines but line2 is omitted',
     70    address: {
     71      "street-address": "line1\n\nline3",
     72    },
     73    expectedResult: {
     74      "street-address": "line1\n\nline3",
     75      "address-line1": "line1",
     76      "address-line2": undefined,
     77      "address-line3": "line3",
     78    },
     79  },
     80  {
     81    description: '"street-address" with 4 lines',
     82    address: {
     83      "street-address": "line1\nline2\nline3\nline4",
     84    },
     85    expectedResult: {
     86      "street-address": "line1\nline2\nline3\nline4",
     87      "address-line1": "line1",
     88      "address-line2": "line2",
     89      "address-line3": "line3 line4",
     90    },
     91  },
     92  {
     93    description: '"street-address" with blank lines',
     94    address: {
     95      "street-address": "line1\n \nline3\n \nline5",
     96    },
     97    expectedResult: {
     98      "street-address": "line1\n \nline3\n \nline5",
     99      "address-line1": "line1",
    100      "address-line2": undefined,
    101      "address-line3": "line3 line5",
    102    },
    103  },
    104 
    105  // Country
    106  {
    107    description: 'Has "country"',
    108    address: {
    109      country: "US",
    110      name: "Timothy John Berners-Lee",
    111    },
    112    expectedResult: {
    113      country: "US",
    114      name: "Timothy John Berners-Lee",
    115      "country-name": "United States",
    116    },
    117  },
    118 
    119  // Tel
    120  {
    121    description: '"tel" with US country code',
    122    address: {
    123      tel: "+16172535702",
    124    },
    125    expectedResult: {
    126      tel: "+16172535702",
    127      "tel-country-code": "+1",
    128      "tel-national": "6172535702",
    129      "tel-area-code": "617",
    130      "tel-local": "2535702",
    131      "tel-local-prefix": "253",
    132      "tel-local-suffix": "5702",
    133    },
    134  },
    135  {
    136    description: '"tel" with TW country code (the components won\'t be parsed)',
    137    address: {
    138      tel: "+886212345678",
    139    },
    140    expectedResult: {
    141      tel: "+886212345678",
    142      "tel-country-code": "+886",
    143      "tel-national": "0212345678",
    144      "tel-area-code": undefined,
    145      "tel-local": undefined,
    146      "tel-local-prefix": undefined,
    147      "tel-local-suffix": undefined,
    148    },
    149  },
    150  {
    151    description: '"tel" without country code so use "US" as default resion',
    152    address: {
    153      tel: "6172535702",
    154    },
    155    expectedResult: {
    156      tel: "+16172535702",
    157      "tel-country-code": "+1",
    158      "tel-national": "6172535702",
    159      "tel-area-code": "617",
    160      "tel-local": "2535702",
    161      "tel-local-prefix": "253",
    162      "tel-local-suffix": "5702",
    163    },
    164  },
    165  {
    166    description: '"tel" without country code but "country" is "TW"',
    167    address: {
    168      tel: "0212345678",
    169      country: "TW",
    170    },
    171    expectedResult: {
    172      tel: "+886212345678",
    173      "tel-country-code": "+886",
    174      "tel-national": "0212345678",
    175      "tel-area-code": undefined,
    176      "tel-local": undefined,
    177      "tel-local-prefix": undefined,
    178      "tel-local-suffix": undefined,
    179    },
    180  },
    181  {
    182    description: '"tel" can\'t be parsed so leave it as-is',
    183    address: {
    184      tel: "12345",
    185    },
    186    expectedResult: {
    187      tel: "12345",
    188      "tel-country-code": undefined,
    189      "tel-national": "12345",
    190      "tel-area-code": undefined,
    191      "tel-local": undefined,
    192      "tel-local-prefix": undefined,
    193      "tel-local-suffix": undefined,
    194    },
    195  },
    196 ];
    197 
    198 const ADDRESS_NORMALIZE_TESTCASES = [
    199  // Name
    200  {
    201    description: 'Has "name", and the split names are omitted',
    202    address: {
    203      name: "Timothy John Berners-Lee",
    204    },
    205    expectedResult: {
    206      name: "Timothy John Berners-Lee",
    207    },
    208  },
    209  {
    210    description: 'Has both "name" and split names',
    211    address: {
    212      name: "Timothy John Berners-Lee",
    213      "given-name": "John",
    214      "family-name": "Doe",
    215    },
    216    expectedResult: {
    217      name: "Timothy John Berners-Lee",
    218    },
    219  },
    220  {
    221    description: 'Has "name", and some of split names are omitted',
    222    address: {
    223      name: "John Doe",
    224      "given-name": "Timothy",
    225    },
    226    expectedResult: {
    227      name: "John Doe",
    228    },
    229  },
    230  {
    231    description: 'Does not have "name", and has split names',
    232    address: {
    233      "given-name": "Timothy",
    234      "additional-name": "John",
    235      "family-name": "Berners-Lee",
    236    },
    237    expectedResult: {
    238      name: "Timothy John Berners-Lee",
    239    },
    240  },
    241  {
    242    description: 'Does not have "name", and has some split names',
    243    address: {
    244      "given-name": "John",
    245      "family-name": "Doe",
    246    },
    247    expectedResult: {
    248      name: "John Doe",
    249    },
    250  },
    251  {
    252    description: 'Does not have "name" and split names',
    253    address: {
    254      organization: "Mozilla",
    255    },
    256    expectedResult: {
    257      name: undefined,
    258      organization: "Mozilla",
    259    },
    260  },
    261 
    262  // Address
    263  {
    264    description: 'Has "address-line1~3" and "street-address" is omitted',
    265    address: {
    266      "address-line1": "line1",
    267      "address-line2": "line2",
    268      "address-line3": "line3",
    269    },
    270    expectedResult: {
    271      "street-address": "line1\nline2\nline3",
    272    },
    273  },
    274  {
    275    description: 'Has both "address-line1~3" and "street-address"',
    276    address: {
    277      "street-address": "street address",
    278      "address-line1": "line1",
    279      "address-line2": "line2",
    280      "address-line3": "line3",
    281    },
    282    expectedResult: {
    283      "street-address": "street address",
    284    },
    285  },
    286  {
    287    description: 'Has "address-line2~3" and single-line "street-address"',
    288    address: {
    289      "street-address": "street address",
    290      "address-line2": "line2",
    291      "address-line3": "line3",
    292    },
    293    expectedResult: {
    294      "street-address": "street address\nline2\nline3",
    295    },
    296  },
    297  {
    298    description: 'Has "address-line2~3" and multiple-line "street-address"',
    299    address: {
    300      "street-address": "street address\nstreet address line 2",
    301      "address-line2": "line2",
    302      "address-line3": "line3",
    303    },
    304    expectedResult: {
    305      "street-address": "street address\nstreet address line 2",
    306    },
    307  },
    308  {
    309    description: 'Has only "address-line1~2"',
    310    address: {
    311      "address-line1": "line1",
    312      "address-line2": "line2",
    313    },
    314    expectedResult: {
    315      "street-address": "line1\nline2",
    316    },
    317  },
    318  {
    319    description: 'Has only "address-line1"',
    320    address: {
    321      "address-line1": "line1",
    322    },
    323    expectedResult: {
    324      "street-address": "line1",
    325    },
    326  },
    327  {
    328    description: 'Has only "address-line2~3"',
    329    address: {
    330      "address-line2": "line2",
    331      "address-line3": "line3",
    332    },
    333    expectedResult: {
    334      "street-address": "\nline2\nline3",
    335    },
    336  },
    337  {
    338    description: 'Has only "address-line2"',
    339    address: {
    340      "address-line2": "line2",
    341    },
    342    expectedResult: {
    343      "street-address": "\nline2",
    344    },
    345  },
    346 
    347  // Country
    348  {
    349    description: 'Has "country" in lowercase',
    350    address: {
    351      country: "us",
    352      name: "name",
    353    },
    354    expectedResult: {
    355      country: "US",
    356      name: "name",
    357    },
    358  },
    359  {
    360    description: 'Has unknown "country"',
    361    address: {
    362      "given-name": "John", // Make sure it won't be an empty record.
    363      country: "AA",
    364    },
    365    expectedResult: {
    366      country: "US",
    367    },
    368  },
    369  {
    370    description: 'Has "country-name"',
    371    address: {
    372      "country-name": "united states",
    373      name: "name",
    374    },
    375    expectedResult: {
    376      country: "US",
    377      "country-name": "United States",
    378      name: "name",
    379    },
    380  },
    381  {
    382    description: 'Has alternative "country-name"',
    383    address: {
    384      "country-name": "america",
    385      name: "name",
    386    },
    387    expectedResult: {
    388      country: "US",
    389      "country-name": "United States",
    390      name: "name",
    391    },
    392  },
    393  {
    394    description: 'Has "country-name" as a substring',
    395    address: {
    396      "country-name": "test america test",
    397      name: "name",
    398    },
    399    expectedResult: {
    400      country: "US",
    401      "country-name": "United States",
    402      name: "name",
    403    },
    404  },
    405  {
    406    description: 'Has "country-name" as part of a word',
    407    address: {
    408      "country-name": "TRUST",
    409      name: "name", // Make sure it won't be an empty record.
    410    },
    411    expectedResult: {
    412      country: "US",
    413      "country-name": "United States",
    414      name: "name",
    415    },
    416  },
    417  {
    418    description: 'Has unknown "country-name"',
    419    address: {
    420      "country-name": "unknown country name",
    421      name: "name", // Make sure it won't be an empty record.
    422    },
    423    expectedResult: {
    424      country: "US",
    425      "country-name": "United States",
    426      name: "name",
    427    },
    428  },
    429  {
    430    description: 'Has "country" and unknown "country-name"',
    431    address: {
    432      country: "us",
    433      "country-name": "unknown country name",
    434      name: "name",
    435    },
    436    expectedResult: {
    437      country: "US",
    438      "country-name": "United States",
    439      name: "name",
    440    },
    441  },
    442  {
    443    description: 'Has "country-name" and unknown "country"',
    444    address: {
    445      country: "AA",
    446      "country-name": "united states",
    447      name: "name",
    448    },
    449    expectedResult: {
    450      country: "US",
    451      "country-name": "United States",
    452      name: "name",
    453    },
    454  },
    455  {
    456    description: 'Has unsupported "country"',
    457    address: {
    458      country: "XX",
    459      name: "name",
    460    },
    461    expectedResult: {
    462      country: "US",
    463      "country-name": "United States",
    464      name: "name",
    465    },
    466  },
    467 
    468  // Tel
    469  {
    470    description: 'Has "tel" with country code',
    471    address: {
    472      tel: "+16172535702",
    473    },
    474    expectedResult: {
    475      tel: "+16172535702",
    476    },
    477  },
    478  {
    479    description: 'Has "tel" without country code but "country" is set',
    480    address: {
    481      tel: "0212345678",
    482      country: "TW",
    483    },
    484    expectedResult: {
    485      tel: "+886212345678",
    486    },
    487  },
    488  {
    489    description:
    490      'Has "tel" without country code and "country" so use "US" as default region',
    491    address: {
    492      tel: "6172535702",
    493    },
    494    expectedResult: {
    495      tel: "+16172535702",
    496    },
    497  },
    498  {
    499    description: '"tel" can\'t be parsed so leave it as-is',
    500    address: {
    501      tel: "12345",
    502    },
    503    expectedResult: {
    504      tel: "12345",
    505    },
    506  },
    507  {
    508    description: 'Has a valid tel-local format "tel"',
    509    address: {
    510      tel: "1234567",
    511    },
    512    expectedResult: {
    513      tel: "1234567",
    514    },
    515  },
    516  {
    517    description: 'Has "tel-national" and "tel-country-code"',
    518    address: {
    519      "tel-national": "0212345678",
    520      "tel-country-code": "+886",
    521    },
    522    expectedResult: {
    523      tel: "+886212345678",
    524    },
    525  },
    526  {
    527    description: 'Has "tel-national" and "country"',
    528    address: {
    529      "tel-national": "0212345678",
    530      country: "TW",
    531    },
    532    expectedResult: {
    533      tel: "+886212345678",
    534    },
    535  },
    536  {
    537    description: 'Has "tel-national", "tel-country-code" and "country"',
    538    address: {
    539      "tel-national": "0212345678",
    540      "tel-country-code": "+886",
    541      country: "US",
    542    },
    543    expectedResult: {
    544      tel: "+886212345678",
    545    },
    546  },
    547  {
    548    description: 'Has "tel-area-code" and "tel-local"',
    549    address: {
    550      "tel-area-code": "617",
    551      "tel-local": "2535702",
    552    },
    553    expectedResult: {
    554      tel: "+16172535702",
    555    },
    556  },
    557  {
    558    description:
    559      'Has "tel-area-code", "tel-local-prefix" and "tel-local-suffix"',
    560    address: {
    561      "tel-area-code": "617",
    562      "tel-local-prefix": "253",
    563      "tel-local-suffix": "5702",
    564    },
    565    expectedResult: {
    566      tel: "+16172535702",
    567    },
    568  },
    569 ];
    570 
    571 const CREDIT_CARD_COMPUTE_TESTCASES = [
    572  // Name
    573  {
    574    description: 'Has "cc-name"',
    575    creditCard: {
    576      "cc-name": "Timothy John Berners-Lee",
    577      "cc-number": "4929001587121045",
    578    },
    579    expectedResult: {
    580      "cc-name": "Timothy John Berners-Lee",
    581      "cc-number": "************1045",
    582      "cc-given-name": "Timothy",
    583      "cc-additional-name": "John",
    584      "cc-family-name": "Berners-Lee",
    585    },
    586  },
    587 
    588  // Card Number
    589  {
    590    description: "Number should be encrypted and masked",
    591    creditCard: {
    592      "cc-number": "4929001587121045",
    593    },
    594    expectedResult: {
    595      "cc-number": "************1045",
    596    },
    597  },
    598 
    599  // Expiration Date
    600  {
    601    description: 'Has "cc-exp-year" and "cc-exp-month"',
    602    creditCard: {
    603      "cc-exp-month": 12,
    604      "cc-exp-year": 2022,
    605      "cc-number": "4929001587121045",
    606    },
    607    expectedResult: {
    608      "cc-exp-month": 12,
    609      "cc-exp-year": 2022,
    610      "cc-exp": "2022-12",
    611      "cc-number": "************1045",
    612    },
    613  },
    614  {
    615    description: 'Has only "cc-exp-month"',
    616    creditCard: {
    617      "cc-exp-month": 12,
    618      "cc-number": "4929001587121045",
    619    },
    620    expectedResult: {
    621      "cc-exp-month": 12,
    622      "cc-exp": undefined,
    623      "cc-number": "************1045",
    624    },
    625  },
    626  {
    627    description: 'Has only "cc-exp-year"',
    628    creditCard: {
    629      "cc-exp-year": 2022,
    630      "cc-number": "4929001587121045",
    631    },
    632    expectedResult: {
    633      "cc-exp-year": 2022,
    634      "cc-exp": undefined,
    635      "cc-number": "************1045",
    636    },
    637  },
    638 ];
    639 
    640 const CREDIT_CARD_NORMALIZE_TESTCASES = [
    641  // Name
    642  {
    643    description: 'Has both "cc-name" and the split name fields',
    644    creditCard: {
    645      "cc-name": "Timothy John Berners-Lee",
    646      "cc-given-name": "John",
    647      "cc-family-name": "Doe",
    648      "cc-number": "4929001587121045",
    649    },
    650    expectedResult: {
    651      "cc-name": "Timothy John Berners-Lee",
    652      "cc-number": "4929001587121045",
    653    },
    654  },
    655  {
    656    description: "Has only the split name fields",
    657    creditCard: {
    658      "cc-given-name": "John",
    659      "cc-family-name": "Doe",
    660      "cc-number": "4929001587121045",
    661    },
    662    expectedResult: {
    663      "cc-name": "John Doe",
    664      "cc-number": "4929001587121045",
    665    },
    666  },
    667 
    668  // Card Number
    669  {
    670    description: "Regular number",
    671    creditCard: {
    672      "cc-number": "4929001587121045",
    673    },
    674    expectedResult: {
    675      "cc-number": "4929001587121045",
    676    },
    677  },
    678  {
    679    description: "Number with spaces",
    680    creditCard: {
    681      "cc-number": "4111 1111  1111 1111",
    682    },
    683    expectedResult: {
    684      "cc-number": "4111111111111111",
    685    },
    686  },
    687  {
    688    description: "Number with hyphens",
    689    creditCard: {
    690      "cc-number": "4111-1111-1111-1111",
    691    },
    692    expectedResult: {
    693      "cc-number": "4111111111111111",
    694    },
    695  },
    696 
    697  // Expiration Date
    698  {
    699    description: 'Has "cc-exp" formatted "yyyy-mm"',
    700    creditCard: {
    701      "cc-number": "4929001587121045",
    702      "cc-exp": "2022-12",
    703    },
    704    expectedResult: {
    705      "cc-exp-month": 12,
    706      "cc-exp-year": 2022,
    707      "cc-number": "4929001587121045",
    708    },
    709  },
    710  {
    711    description: 'Has "cc-exp" formatted "yyyy/mm"',
    712    creditCard: {
    713      "cc-number": "4929001587121045",
    714      "cc-exp": "2022/12",
    715    },
    716    expectedResult: {
    717      "cc-exp-month": 12,
    718      "cc-exp-year": 2022,
    719      "cc-number": "4929001587121045",
    720    },
    721  },
    722  {
    723    description: 'Has "cc-exp" formatted "yyyy-m"',
    724    creditCard: {
    725      "cc-number": "4929001587121045",
    726      "cc-exp": "2022-3",
    727    },
    728    expectedResult: {
    729      "cc-exp-month": 3,
    730      "cc-exp-year": 2022,
    731      "cc-number": "4929001587121045",
    732    },
    733  },
    734  {
    735    description: 'Has "cc-exp" formatted "yyyy/m"',
    736    creditCard: {
    737      "cc-number": "4929001587121045",
    738      "cc-exp": "2022/3",
    739    },
    740    expectedResult: {
    741      "cc-exp-month": 3,
    742      "cc-exp-year": 2022,
    743      "cc-number": "4929001587121045",
    744    },
    745  },
    746  {
    747    description: 'Has "cc-exp" formatted "mm-yyyy"',
    748    creditCard: {
    749      "cc-number": "4929001587121045",
    750      "cc-exp": "12-2022",
    751    },
    752    expectedResult: {
    753      "cc-exp-month": 12,
    754      "cc-exp-year": 2022,
    755      "cc-number": "4929001587121045",
    756    },
    757  },
    758  {
    759    description: 'Has "cc-exp" formatted "mm/yyyy"',
    760    creditCard: {
    761      "cc-number": "4929001587121045",
    762      "cc-exp": "12/2022",
    763    },
    764    expectedResult: {
    765      "cc-exp-month": 12,
    766      "cc-exp-year": 2022,
    767      "cc-number": "4929001587121045",
    768    },
    769  },
    770  {
    771    description: 'Has "cc-exp" formatted "m-yyyy"',
    772    creditCard: {
    773      "cc-number": "4929001587121045",
    774      "cc-exp": "3-2022",
    775    },
    776    expectedResult: {
    777      "cc-exp-month": 3,
    778      "cc-exp-year": 2022,
    779      "cc-number": "4929001587121045",
    780    },
    781  },
    782  {
    783    description: 'Has "cc-exp" formatted "m/yyyy"',
    784    creditCard: {
    785      "cc-number": "4929001587121045",
    786      "cc-exp": "3/2022",
    787    },
    788    expectedResult: {
    789      "cc-exp-month": 3,
    790      "cc-exp-year": 2022,
    791      "cc-number": "4929001587121045",
    792    },
    793  },
    794  {
    795    description: 'Has "cc-exp" formatted "mm-yy"',
    796    creditCard: {
    797      "cc-number": "4929001587121045",
    798      "cc-exp": "12-22",
    799    },
    800    expectedResult: {
    801      "cc-exp-month": 12,
    802      "cc-exp-year": 2022,
    803      "cc-number": "4929001587121045",
    804    },
    805  },
    806  {
    807    description: 'Has "cc-exp" formatted "mm/yy"',
    808    creditCard: {
    809      "cc-number": "4929001587121045",
    810      "cc-exp": "12/22",
    811    },
    812    expectedResult: {
    813      "cc-exp-month": 12,
    814      "cc-exp-year": 2022,
    815      "cc-number": "4929001587121045",
    816    },
    817  },
    818  {
    819    description: 'Has "cc-exp" formatted "yy-mm"',
    820    creditCard: {
    821      "cc-number": "4929001587121045",
    822      "cc-exp": "22-12",
    823    },
    824    expectedResult: {
    825      "cc-exp-month": 12,
    826      "cc-exp-year": 2022,
    827      "cc-number": "4929001587121045",
    828    },
    829  },
    830  {
    831    description: 'Has "cc-exp" formatted "yy/mm"',
    832    creditCard: {
    833      "cc-exp": "22/12",
    834      "cc-number": "4929001587121045",
    835    },
    836    expectedResult: {
    837      "cc-exp-month": 12,
    838      "cc-exp-year": 2022,
    839      "cc-number": "4929001587121045",
    840    },
    841  },
    842  {
    843    description: 'Has "cc-exp" formatted "mmyy"',
    844    creditCard: {
    845      "cc-exp": "1222",
    846      "cc-number": "4929001587121045",
    847    },
    848    expectedResult: {
    849      "cc-exp-month": 12,
    850      "cc-exp-year": 2022,
    851      "cc-number": "4929001587121045",
    852    },
    853  },
    854  {
    855    description: 'Has "cc-exp" formatted "yymm"',
    856    creditCard: {
    857      "cc-exp": "2212",
    858      "cc-number": "4929001587121045",
    859    },
    860    expectedResult: {
    861      "cc-exp-month": 12,
    862      "cc-exp-year": 2022,
    863      "cc-number": "4929001587121045",
    864    },
    865  },
    866  {
    867    description: 'Has "cc-exp" with spaces',
    868    creditCard: {
    869      "cc-exp": "  2033-11  ",
    870      "cc-number": "4929001587121045",
    871    },
    872    expectedResult: {
    873      "cc-exp-month": 11,
    874      "cc-exp-year": 2033,
    875      "cc-number": "4929001587121045",
    876    },
    877  },
    878  {
    879    description: 'Has invalid "cc-exp"',
    880    creditCard: {
    881      "cc-number": "4111111111111111", // Make sure it won't be an empty record.
    882      "cc-exp": "99-9999",
    883    },
    884    expectedResult: {
    885      "cc-exp-month": undefined,
    886      "cc-exp-year": undefined,
    887    },
    888  },
    889  {
    890    description: 'Has both "cc-exp-*" and "cc-exp"',
    891    creditCard: {
    892      "cc-exp": "2022-12",
    893      "cc-exp-month": 3,
    894      "cc-exp-year": 2030,
    895      "cc-number": "4929001587121045",
    896    },
    897    expectedResult: {
    898      "cc-exp-month": 3,
    899      "cc-exp-year": 2030,
    900      "cc-number": "4929001587121045",
    901    },
    902  },
    903  {
    904    description: 'Has only "cc-exp-year" and "cc-exp"',
    905    creditCard: {
    906      "cc-exp": "2022-12",
    907      "cc-exp-year": 2030,
    908      "cc-number": "4929001587121045",
    909    },
    910    expectedResult: {
    911      "cc-exp-month": 12,
    912      "cc-exp-year": 2022,
    913      "cc-number": "4929001587121045",
    914    },
    915  },
    916  {
    917    description: 'Has only "cc-exp-month" and "cc-exp"',
    918    creditCard: {
    919      "cc-exp": "2022-12",
    920      "cc-exp-month": 3,
    921      "cc-number": "4929001587121045",
    922    },
    923    expectedResult: {
    924      "cc-exp-month": 12,
    925      "cc-exp-year": 2022,
    926      "cc-number": "4929001587121045",
    927    },
    928  },
    929 ];
    930 
    931 let do_check_record_matches = (expectedRecord, record) => {
    932  for (let key in expectedRecord) {
    933    Assert.equal(expectedRecord[key], record[key]);
    934  }
    935 };
    936 
    937 add_task(async function test_computeAddressFields() {
    938  let path = getTempFile(TEST_STORE_FILE_NAME).path;
    939 
    940  let profileStorage = new FormAutofillStorage(path);
    941  await profileStorage.initialize();
    942 
    943  for (let testcase of ADDRESS_COMPUTE_TESTCASES) {
    944    info("Verify testcase: " + testcase.description);
    945 
    946    let guid = await profileStorage.addresses.add(testcase.address);
    947    let address = await profileStorage.addresses.get(guid);
    948    do_check_record_matches(testcase.expectedResult, address);
    949 
    950    profileStorage.addresses.remove(guid);
    951  }
    952 
    953  await profileStorage._finalize();
    954 });
    955 
    956 add_task(async function test_normalizeAddressFields() {
    957  let path = getTempFile(TEST_STORE_FILE_NAME).path;
    958 
    959  let profileStorage = new FormAutofillStorage(path);
    960  await profileStorage.initialize();
    961 
    962  for (let testcase of ADDRESS_NORMALIZE_TESTCASES) {
    963    info("Verify testcase: " + testcase.description);
    964 
    965    let guid = await profileStorage.addresses.add(testcase.address);
    966    let address = await profileStorage.addresses.get(guid);
    967    do_check_record_matches(testcase.expectedResult, address);
    968 
    969    profileStorage.addresses.remove(guid);
    970  }
    971 
    972  await profileStorage._finalize();
    973 });
    974 
    975 add_task(async function test_computeCreditCardFields() {
    976  let path = getTempFile(TEST_STORE_FILE_NAME).path;
    977 
    978  let profileStorage = new FormAutofillStorage(path);
    979  await profileStorage.initialize();
    980 
    981  for (let testcase of CREDIT_CARD_COMPUTE_TESTCASES) {
    982    info("Verify testcase: " + testcase.description);
    983 
    984    let guid = await profileStorage.creditCards.add(testcase.creditCard);
    985    let creditCard = await profileStorage.creditCards.get(guid);
    986    do_check_record_matches(testcase.expectedResult, creditCard);
    987 
    988    profileStorage.creditCards.remove(guid);
    989  }
    990 
    991  await profileStorage._finalize();
    992 });
    993 
    994 add_task(async function test_normalizeCreditCardFields() {
    995  let path = getTempFile(TEST_STORE_FILE_NAME).path;
    996 
    997  let profileStorage = new FormAutofillStorage(path);
    998  await profileStorage.initialize();
    999 
   1000  for (let testcase of CREDIT_CARD_NORMALIZE_TESTCASES) {
   1001    info("Verify testcase: " + testcase.description);
   1002 
   1003    let guid = await profileStorage.creditCards.add(testcase.creditCard);
   1004    let creditCard = await profileStorage.creditCards.get(guid, {
   1005      rawData: true,
   1006    });
   1007    do_check_record_matches(testcase.expectedResult, creditCard);
   1008 
   1009    profileStorage.creditCards.remove(guid);
   1010  }
   1011 
   1012  await profileStorage._finalize();
   1013 });