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"/>
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"]],
42 info(
"Run test: " + JSON.stringify(val) +
"\n");
44 let params = new URLSearchParams(val.input);
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);
56 for (let param of params) {
57 compareArray(param, val.output[i++]);