Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / url / tests / test_urlSearchParams_sorting.html
bloba608e8bc13b59c51e4721301fd6dcd0a196b8ee7
2 <!DOCTYPE HTML>
3 <html>
4 <head>
5 <meta charset="utf-8">
6 <title>Test for URLSearchParams.sort()</title>
7 <script src="/tests/SimpleTest/SimpleTest.js"></script>
8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
9 </head>
10 <body>
11 <script type="application/javascript">
13 function compareArray(a, b) {
14 is(a.length, b.length, "Length matches");
15 for (let i = 0; i < a.length; ++i) {
16 is(a[i], b[i], "Values " + i + " match");
22 "input": "z=b&a=b&z=a&a=a",
23 "output": [["a", "b"], ["a", "a"], ["z", "b"], ["z", "a"]],
26 "input": "\uFFFD=x&\uFFFC&\uFFFD=a",
27 "output": [["\uFFFC", ""], ["\uFFFD", "x"], ["\uFFFD", "a"]],
30 "input": "ffi&🌈", // 🌈 > code point, but < code unit because two code units
31 "output": [["🌈", ""], ["ffi", ""]],
34 "input": "é&e\uFFFD&e\u0301",
35 "output": [["e\u0301", ""], ["e\uFFFD", ""], ["é", ""]],
38 "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",
39 "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"]],
41 ].forEach((val) => {
42 info("Run test: " + JSON.stringify(val) + "\n");
44 let params = new URLSearchParams(val.input);
45 params.sort();
47 let i = 0;
48 for (let param of params) {
49 compareArray(param, val.output[i++]);
52 let url = new URL("?" + val.input, "https://example/");
53 url.searchParams.sort();
54 params = new URLSearchParams(url.search);
55 i = 0;
56 for (let param of params) {
57 compareArray(param, val.output[i++]);
59 });
61 </script>
62 </body>
63 </html>