tor-browser

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

test_urlSearchParams_sorting.html (1666B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test for URLSearchParams.sort()</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      8 </head>
      9 <body>
     10 <script type="application/javascript">
     11 
     12 function compareArray(a, b) {
     13  is(a.length, b.length, "Length matches");
     14  for (let i = 0; i < a.length; ++i) {
     15    is(a[i], b[i], "Values " + i + " match");
     16  }
     17 }
     18 
     19 [
     20  {
     21    "input": "z=b&a=b&z=a&a=a",
     22    "output": [["a", "b"], ["a", "a"], ["z", "b"], ["z", "a"]],
     23  },
     24  {
     25    "input": "\uFFFD=x&\uFFFC&\uFFFD=a",
     26    "output": [["\uFFFC", ""], ["\uFFFD", "x"], ["\uFFFD", "a"]],
     27  },
     28  {
     29    "input": "ffi&🌈", // 🌈 > code point, but < code unit because two code units
     30    "output": [["🌈", ""], ["ffi", ""]],
     31  },
     32  {
     33    "input": "é&e\uFFFD&e\u0301",
     34    "output": [["e\u0301", ""], ["e\uFFFD", ""], ["é", ""]],
     35  },
     36  {
     37    "input": "z=z&a=a&z=y&a=b&z=x&a=c&z=w&a=d&z=v&a=e&z=u&a=f&z=t&a=g",
     38    "output": [["a", "a"], ["a", "b"], ["a", "c"], ["a", "d"], ["a", "e"], ["a", "f"], ["a", "g"], ["z", "z"], ["z", "y"], ["z", "x"], ["z", "w"], ["z", "v"], ["z", "u"], ["z", "t"]],
     39  },
     40 ].forEach((val) => {
     41  info("Run test: " + JSON.stringify(val) + "\n");
     42 
     43  let params = new URLSearchParams(val.input);
     44  params.sort();
     45 
     46  let i = 0;
     47  for (let param of params) {
     48    compareArray(param, val.output[i++]);
     49  }
     50 
     51  let url = new URL("?" + val.input, "https://example/");
     52  url.searchParams.sort();
     53  params = new URLSearchParams(url.search);
     54  i = 0;
     55  for (let param of params) {
     56    compareArray(param, val.output[i++]);
     57  }
     58 });
     59 
     60 </script>
     61 </body>
     62 </html>