11cb0ef41Sopenharmony_citest(function() { 21cb0ef41Sopenharmony_ci var params = new URLSearchParams(); 31cb0ef41Sopenharmony_ci assert_equals(params + '', ''); 41cb0ef41Sopenharmony_ci params = new URLSearchParams(''); 51cb0ef41Sopenharmony_ci assert_equals(params + '', ''); 61cb0ef41Sopenharmony_ci params = new URLSearchParams('a=b'); 71cb0ef41Sopenharmony_ci assert_equals(params + '', 'a=b'); 81cb0ef41Sopenharmony_ci params = new URLSearchParams(params); 91cb0ef41Sopenharmony_ci assert_equals(params + '', 'a=b'); 101cb0ef41Sopenharmony_ci}, 'Basic URLSearchParams construction'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_citest(function() { 131cb0ef41Sopenharmony_ci var params = new URLSearchParams() 141cb0ef41Sopenharmony_ci assert_equals(params.toString(), "") 151cb0ef41Sopenharmony_ci}, "URLSearchParams constructor, no arguments") 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_citest(function () { 181cb0ef41Sopenharmony_ci var params = new URLSearchParams("?a=b") 191cb0ef41Sopenharmony_ci assert_equals(params.toString(), "a=b") 201cb0ef41Sopenharmony_ci}, 'URLSearchParams constructor, remove leading "?"') 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_citest(() => { 231cb0ef41Sopenharmony_ci var params = new URLSearchParams(DOMException); 241cb0ef41Sopenharmony_ci assert_equals(params.toString(), "INDEX_SIZE_ERR=1&DOMSTRING_SIZE_ERR=2&HIERARCHY_REQUEST_ERR=3&WRONG_DOCUMENT_ERR=4&INVALID_CHARACTER_ERR=5&NO_DATA_ALLOWED_ERR=6&NO_MODIFICATION_ALLOWED_ERR=7&NOT_FOUND_ERR=8&NOT_SUPPORTED_ERR=9&INUSE_ATTRIBUTE_ERR=10&INVALID_STATE_ERR=11&SYNTAX_ERR=12&INVALID_MODIFICATION_ERR=13&NAMESPACE_ERR=14&INVALID_ACCESS_ERR=15&VALIDATION_ERR=16&TYPE_MISMATCH_ERR=17&SECURITY_ERR=18&NETWORK_ERR=19&ABORT_ERR=20&URL_MISMATCH_ERR=21"A_EXCEEDED_ERR=22&TIMEOUT_ERR=23&INVALID_NODE_TYPE_ERR=24&DATA_CLONE_ERR=25") 251cb0ef41Sopenharmony_ci assert_throws_js(TypeError, () => new URLSearchParams(DOMException.prototype), 261cb0ef41Sopenharmony_ci "Constructing a URLSearchParams from DOMException.prototype should throw due to branding checks"); 271cb0ef41Sopenharmony_ci}, "URLSearchParams constructor, DOMException as argument") 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_citest(() => { 301cb0ef41Sopenharmony_ci var params = new URLSearchParams(''); 311cb0ef41Sopenharmony_ci assert_true(params != null, 'constructor returned non-null value.'); 321cb0ef41Sopenharmony_ci assert_equals(Object.getPrototypeOf(params), URLSearchParams.prototype, 'expected URLSearchParams.prototype as prototype.'); 331cb0ef41Sopenharmony_ci}, "URLSearchParams constructor, empty string as argument") 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_citest(() => { 361cb0ef41Sopenharmony_ci var params = new URLSearchParams({}); 371cb0ef41Sopenharmony_ci assert_equals(params + '', ""); 381cb0ef41Sopenharmony_ci}, 'URLSearchParams constructor, {} as argument'); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_citest(function() { 411cb0ef41Sopenharmony_ci var params = new URLSearchParams('a=b'); 421cb0ef41Sopenharmony_ci assert_true(params != null, 'constructor returned non-null value.'); 431cb0ef41Sopenharmony_ci assert_true(params.has('a'), 'Search params object has name "a"'); 441cb0ef41Sopenharmony_ci assert_false(params.has('b'), 'Search params object has not got name "b"'); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci params = new URLSearchParams('a=b&c'); 471cb0ef41Sopenharmony_ci assert_true(params != null, 'constructor returned non-null value.'); 481cb0ef41Sopenharmony_ci assert_true(params.has('a'), 'Search params object has name "a"'); 491cb0ef41Sopenharmony_ci assert_true(params.has('c'), 'Search params object has name "c"'); 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci params = new URLSearchParams('&a&&& &&&&&a+b=& c&m%c3%b8%c3%b8'); 521cb0ef41Sopenharmony_ci assert_true(params != null, 'constructor returned non-null value.'); 531cb0ef41Sopenharmony_ci assert_true(params.has('a'), 'Search params object has name "a"'); 541cb0ef41Sopenharmony_ci assert_true(params.has('a b'), 'Search params object has name "a b"'); 551cb0ef41Sopenharmony_ci assert_true(params.has(' '), 'Search params object has name " "'); 561cb0ef41Sopenharmony_ci assert_false(params.has('c'), 'Search params object did not have the name "c"'); 571cb0ef41Sopenharmony_ci assert_true(params.has(' c'), 'Search params object has name " c"'); 581cb0ef41Sopenharmony_ci assert_true(params.has('møø'), 'Search params object has name "møø"'); 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_ci params = new URLSearchParams('id=0&value=%'); 611cb0ef41Sopenharmony_ci assert_true(params != null, 'constructor returned non-null value.'); 621cb0ef41Sopenharmony_ci assert_true(params.has('id'), 'Search params object has name "id"'); 631cb0ef41Sopenharmony_ci assert_true(params.has('value'), 'Search params object has name "value"'); 641cb0ef41Sopenharmony_ci assert_equals(params.get('id'), '0'); 651cb0ef41Sopenharmony_ci assert_equals(params.get('value'), '%'); 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci params = new URLSearchParams('b=%2sf%2a'); 681cb0ef41Sopenharmony_ci assert_true(params != null, 'constructor returned non-null value.'); 691cb0ef41Sopenharmony_ci assert_true(params.has('b'), 'Search params object has name "b"'); 701cb0ef41Sopenharmony_ci assert_equals(params.get('b'), '%2sf*'); 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_ci params = new URLSearchParams('b=%2%2af%2a'); 731cb0ef41Sopenharmony_ci assert_true(params != null, 'constructor returned non-null value.'); 741cb0ef41Sopenharmony_ci assert_true(params.has('b'), 'Search params object has name "b"'); 751cb0ef41Sopenharmony_ci assert_equals(params.get('b'), '%2*f*'); 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci params = new URLSearchParams('b=%%2a'); 781cb0ef41Sopenharmony_ci assert_true(params != null, 'constructor returned non-null value.'); 791cb0ef41Sopenharmony_ci assert_true(params.has('b'), 'Search params object has name "b"'); 801cb0ef41Sopenharmony_ci assert_equals(params.get('b'), '%*'); 811cb0ef41Sopenharmony_ci}, 'URLSearchParams constructor, string.'); 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_citest(function() { 841cb0ef41Sopenharmony_ci var seed = new URLSearchParams('a=b&c=d'); 851cb0ef41Sopenharmony_ci var params = new URLSearchParams(seed); 861cb0ef41Sopenharmony_ci assert_true(params != null, 'constructor returned non-null value.'); 871cb0ef41Sopenharmony_ci assert_equals(params.get('a'), 'b'); 881cb0ef41Sopenharmony_ci assert_equals(params.get('c'), 'd'); 891cb0ef41Sopenharmony_ci assert_false(params.has('d')); 901cb0ef41Sopenharmony_ci // The name-value pairs are copied when created; later updates 911cb0ef41Sopenharmony_ci // should not be observable. 921cb0ef41Sopenharmony_ci seed.append('e', 'f'); 931cb0ef41Sopenharmony_ci assert_false(params.has('e')); 941cb0ef41Sopenharmony_ci params.append('g', 'h'); 951cb0ef41Sopenharmony_ci assert_false(seed.has('g')); 961cb0ef41Sopenharmony_ci}, 'URLSearchParams constructor, object.'); 971cb0ef41Sopenharmony_ci 981cb0ef41Sopenharmony_citest(function() { 991cb0ef41Sopenharmony_ci var formData = new FormData() 1001cb0ef41Sopenharmony_ci formData.append('a', 'b') 1011cb0ef41Sopenharmony_ci formData.append('c', 'd') 1021cb0ef41Sopenharmony_ci var params = new URLSearchParams(formData); 1031cb0ef41Sopenharmony_ci assert_true(params != null, 'constructor returned non-null value.'); 1041cb0ef41Sopenharmony_ci assert_equals(params.get('a'), 'b'); 1051cb0ef41Sopenharmony_ci assert_equals(params.get('c'), 'd'); 1061cb0ef41Sopenharmony_ci assert_false(params.has('d')); 1071cb0ef41Sopenharmony_ci // The name-value pairs are copied when created; later updates 1081cb0ef41Sopenharmony_ci // should not be observable. 1091cb0ef41Sopenharmony_ci formData.append('e', 'f'); 1101cb0ef41Sopenharmony_ci assert_false(params.has('e')); 1111cb0ef41Sopenharmony_ci params.append('g', 'h'); 1121cb0ef41Sopenharmony_ci assert_false(formData.has('g')); 1131cb0ef41Sopenharmony_ci}, 'URLSearchParams constructor, FormData.'); 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_citest(function() { 1161cb0ef41Sopenharmony_ci var params = new URLSearchParams('a=b+c'); 1171cb0ef41Sopenharmony_ci assert_equals(params.get('a'), 'b c'); 1181cb0ef41Sopenharmony_ci params = new URLSearchParams('a+b=c'); 1191cb0ef41Sopenharmony_ci assert_equals(params.get('a b'), 'c'); 1201cb0ef41Sopenharmony_ci}, 'Parse +'); 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_citest(function() { 1231cb0ef41Sopenharmony_ci const testValue = '+15555555555'; 1241cb0ef41Sopenharmony_ci const params = new URLSearchParams(); 1251cb0ef41Sopenharmony_ci params.set('query', testValue); 1261cb0ef41Sopenharmony_ci var newParams = new URLSearchParams(params.toString()); 1271cb0ef41Sopenharmony_ci 1281cb0ef41Sopenharmony_ci assert_equals(params.toString(), 'query=%2B15555555555'); 1291cb0ef41Sopenharmony_ci assert_equals(params.get('query'), testValue); 1301cb0ef41Sopenharmony_ci assert_equals(newParams.get('query'), testValue); 1311cb0ef41Sopenharmony_ci}, 'Parse encoded +'); 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_citest(function() { 1341cb0ef41Sopenharmony_ci var params = new URLSearchParams('a=b c'); 1351cb0ef41Sopenharmony_ci assert_equals(params.get('a'), 'b c'); 1361cb0ef41Sopenharmony_ci params = new URLSearchParams('a b=c'); 1371cb0ef41Sopenharmony_ci assert_equals(params.get('a b'), 'c'); 1381cb0ef41Sopenharmony_ci}, 'Parse space'); 1391cb0ef41Sopenharmony_ci 1401cb0ef41Sopenharmony_citest(function() { 1411cb0ef41Sopenharmony_ci var params = new URLSearchParams('a=b%20c'); 1421cb0ef41Sopenharmony_ci assert_equals(params.get('a'), 'b c'); 1431cb0ef41Sopenharmony_ci params = new URLSearchParams('a%20b=c'); 1441cb0ef41Sopenharmony_ci assert_equals(params.get('a b'), 'c'); 1451cb0ef41Sopenharmony_ci}, 'Parse %20'); 1461cb0ef41Sopenharmony_ci 1471cb0ef41Sopenharmony_citest(function() { 1481cb0ef41Sopenharmony_ci var params = new URLSearchParams('a=b\0c'); 1491cb0ef41Sopenharmony_ci assert_equals(params.get('a'), 'b\0c'); 1501cb0ef41Sopenharmony_ci params = new URLSearchParams('a\0b=c'); 1511cb0ef41Sopenharmony_ci assert_equals(params.get('a\0b'), 'c'); 1521cb0ef41Sopenharmony_ci}, 'Parse \\0'); 1531cb0ef41Sopenharmony_ci 1541cb0ef41Sopenharmony_citest(function() { 1551cb0ef41Sopenharmony_ci var params = new URLSearchParams('a=b%00c'); 1561cb0ef41Sopenharmony_ci assert_equals(params.get('a'), 'b\0c'); 1571cb0ef41Sopenharmony_ci params = new URLSearchParams('a%00b=c'); 1581cb0ef41Sopenharmony_ci assert_equals(params.get('a\0b'), 'c'); 1591cb0ef41Sopenharmony_ci}, 'Parse %00'); 1601cb0ef41Sopenharmony_ci 1611cb0ef41Sopenharmony_citest(function() { 1621cb0ef41Sopenharmony_ci var params = new URLSearchParams('a=b\u2384'); 1631cb0ef41Sopenharmony_ci assert_equals(params.get('a'), 'b\u2384'); 1641cb0ef41Sopenharmony_ci params = new URLSearchParams('a\u2384b=c'); 1651cb0ef41Sopenharmony_ci assert_equals(params.get('a\u2384b'), 'c'); 1661cb0ef41Sopenharmony_ci}, 'Parse \u2384'); // Unicode Character 'COMPOSITION SYMBOL' (U+2384) 1671cb0ef41Sopenharmony_ci 1681cb0ef41Sopenharmony_citest(function() { 1691cb0ef41Sopenharmony_ci var params = new URLSearchParams('a=b%e2%8e%84'); 1701cb0ef41Sopenharmony_ci assert_equals(params.get('a'), 'b\u2384'); 1711cb0ef41Sopenharmony_ci params = new URLSearchParams('a%e2%8e%84b=c'); 1721cb0ef41Sopenharmony_ci assert_equals(params.get('a\u2384b'), 'c'); 1731cb0ef41Sopenharmony_ci}, 'Parse %e2%8e%84'); // Unicode Character 'COMPOSITION SYMBOL' (U+2384) 1741cb0ef41Sopenharmony_ci 1751cb0ef41Sopenharmony_citest(function() { 1761cb0ef41Sopenharmony_ci var params = new URLSearchParams('a=b\uD83D\uDCA9c'); 1771cb0ef41Sopenharmony_ci assert_equals(params.get('a'), 'b\uD83D\uDCA9c'); 1781cb0ef41Sopenharmony_ci params = new URLSearchParams('a\uD83D\uDCA9b=c'); 1791cb0ef41Sopenharmony_ci assert_equals(params.get('a\uD83D\uDCA9b'), 'c'); 1801cb0ef41Sopenharmony_ci}, 'Parse \uD83D\uDCA9'); // Unicode Character 'PILE OF POO' (U+1F4A9) 1811cb0ef41Sopenharmony_ci 1821cb0ef41Sopenharmony_citest(function() { 1831cb0ef41Sopenharmony_ci var params = new URLSearchParams('a=b%f0%9f%92%a9c'); 1841cb0ef41Sopenharmony_ci assert_equals(params.get('a'), 'b\uD83D\uDCA9c'); 1851cb0ef41Sopenharmony_ci params = new URLSearchParams('a%f0%9f%92%a9b=c'); 1861cb0ef41Sopenharmony_ci assert_equals(params.get('a\uD83D\uDCA9b'), 'c'); 1871cb0ef41Sopenharmony_ci}, 'Parse %f0%9f%92%a9'); // Unicode Character 'PILE OF POO' (U+1F4A9) 1881cb0ef41Sopenharmony_ci 1891cb0ef41Sopenharmony_citest(function() { 1901cb0ef41Sopenharmony_ci var params = new URLSearchParams([]); 1911cb0ef41Sopenharmony_ci assert_true(params != null, 'constructor returned non-null value.'); 1921cb0ef41Sopenharmony_ci params = new URLSearchParams([['a', 'b'], ['c', 'd']]); 1931cb0ef41Sopenharmony_ci assert_equals(params.get("a"), "b"); 1941cb0ef41Sopenharmony_ci assert_equals(params.get("c"), "d"); 1951cb0ef41Sopenharmony_ci assert_throws_js(TypeError, function() { new URLSearchParams([[1]]); }); 1961cb0ef41Sopenharmony_ci assert_throws_js(TypeError, function() { new URLSearchParams([[1,2,3]]); }); 1971cb0ef41Sopenharmony_ci}, "Constructor with sequence of sequences of strings"); 1981cb0ef41Sopenharmony_ci 1991cb0ef41Sopenharmony_ci[ 2001cb0ef41Sopenharmony_ci { "input": {"+": "%C2"}, "output": [["+", "%C2"]], "name": "object with +" }, 2011cb0ef41Sopenharmony_ci { "input": {c: "x", a: "?"}, "output": [["c", "x"], ["a", "?"]], "name": "object with two keys" }, 2021cb0ef41Sopenharmony_ci { "input": [["c", "x"], ["a", "?"]], "output": [["c", "x"], ["a", "?"]], "name": "array with two keys" }, 2031cb0ef41Sopenharmony_ci { "input": {"\uD835x": "1", "xx": "2", "\uD83Dx": "3"}, "output": [["\uFFFDx", "3"], ["xx", "2"]], "name": "2 unpaired surrogates (no trailing)" }, 2041cb0ef41Sopenharmony_ci { "input": {"x\uDC53": "1", "x\uDC5C": "2", "x\uDC65": "3"}, "output": [["x\uFFFD", "3"]], "name": "3 unpaired surrogates (no leading)" }, 2051cb0ef41Sopenharmony_ci { "input": {"a\0b": "42", "c\uD83D": "23", "d\u1234": "foo"}, "output": [["a\0b", "42"], ["c\uFFFD", "23"], ["d\u1234", "foo"]], "name": "object with NULL, non-ASCII, and surrogate keys" } 2061cb0ef41Sopenharmony_ci].forEach((val) => { 2071cb0ef41Sopenharmony_ci test(() => { 2081cb0ef41Sopenharmony_ci let params = new URLSearchParams(val.input), 2091cb0ef41Sopenharmony_ci i = 0 2101cb0ef41Sopenharmony_ci for (let param of params) { 2111cb0ef41Sopenharmony_ci assert_array_equals(param, val.output[i]) 2121cb0ef41Sopenharmony_ci i++ 2131cb0ef41Sopenharmony_ci } 2141cb0ef41Sopenharmony_ci }, "Construct with " + val.name) 2151cb0ef41Sopenharmony_ci}) 2161cb0ef41Sopenharmony_ci 2171cb0ef41Sopenharmony_citest(() => { 2181cb0ef41Sopenharmony_ci var params = new URLSearchParams() 2191cb0ef41Sopenharmony_ci params[Symbol.iterator] = function *() { 2201cb0ef41Sopenharmony_ci yield ["a", "b"] 2211cb0ef41Sopenharmony_ci } 2221cb0ef41Sopenharmony_ci let params2 = new URLSearchParams(params) 2231cb0ef41Sopenharmony_ci assert_equals(params2.get("a"), "b") 2241cb0ef41Sopenharmony_ci}, "Custom [Symbol.iterator]") 225