tor-browser

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

test_toOneLineAddress.js (1306B)


      1 "use strict";
      2 
      3 var FormAutofillUtils;
      4 add_setup(async () => {
      5  ({ FormAutofillUtils } = ChromeUtils.importESModule(
      6    "resource://gre/modules/shared/FormAutofillUtils.sys.mjs"
      7  ));
      8 });
      9 
     10 add_task(async function test_getCategoriesFromFieldNames() {
     11  const TEST_CASES = [
     12    {
     13      strings: ["A", "B", "C", "D"],
     14      expectedValue: "A B C D",
     15    },
     16    {
     17      strings: ["A", "B", "", "D"],
     18      expectedValue: "A B D",
     19    },
     20    {
     21      strings: ["", "B", "", "D"],
     22      expectedValue: "B D",
     23    },
     24    {
     25      strings: [null, "B", " ", "D"],
     26      expectedValue: "B D",
     27    },
     28    {
     29      strings: "A B C",
     30      expectedValue: "A B C",
     31    },
     32    {
     33      strings: "A\nB\n\n\nC",
     34      expectedValue: "A B C",
     35    },
     36    {
     37      strings: "A B \nC",
     38      expectedValue: "A B C",
     39    },
     40    {
     41      strings: "A-B-C",
     42      expectedValue: "A B C",
     43      delimiter: "-",
     44    },
     45    {
     46      strings: "A B\n \nC",
     47      expectedValue: "A B C",
     48    },
     49    {
     50      strings: null,
     51      expectedValue: "",
     52    },
     53  ];
     54 
     55  for (let tc of TEST_CASES) {
     56    let result;
     57    if (tc.delimiter) {
     58      result = FormAutofillUtils.toOneLineAddress(tc.strings, tc.delimiter);
     59    } else {
     60      result = FormAutofillUtils.toOneLineAddress(tc.strings);
     61    }
     62    Assert.equal(result, tc.expectedValue);
     63  }
     64 });