tor-browser

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

browser_jsonview_encoding.js (1319B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 add_task(async function () {
      7  info("Test JSON encoding started");
      8 
      9  const bom = "%EF%BB%BF"; // UTF-8 BOM
     10  const tests = [
     11    {
     12      input: bom,
     13      output: "",
     14    },
     15    {
     16      input: "%FE%FF", // UTF-16BE BOM
     17      output: "\uFFFD\uFFFD",
     18    },
     19    {
     20      input: "%FF%FE", // UTF-16LE BOM
     21      output: "\uFFFD\uFFFD",
     22    },
     23    {
     24      input: bom + "%30",
     25      output: "0",
     26    },
     27    {
     28      input: bom + bom,
     29      output: "\uFEFF",
     30    },
     31    {
     32      input: "%00%61",
     33      output: "\u0000a",
     34    },
     35    {
     36      input: "%61%00",
     37      output: "a\u0000",
     38    },
     39    {
     40      input: "%30%FF",
     41      output: "0�",
     42    },
     43    {
     44      input: "%C3%A0",
     45      output: "à",
     46    },
     47    {
     48      input: "%E2%9D%A4",
     49      output: "❤",
     50    },
     51    {
     52      input: "%F0%9F%9A%80",
     53      output: "🚀",
     54    },
     55  ];
     56 
     57  for (const { input, output } of tests) {
     58    info("Test decoding of " + JSON.stringify(input) + ".");
     59 
     60    await addJsonViewTab("data:application/json," + input);
     61    await selectJsonViewContentTab("rawdata");
     62 
     63    // Check displayed data.
     64    const data = await getElementText(".textPanelBox .data");
     65    is(data, output, "The right data has been received.");
     66  }
     67 });