mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 07:31:47 +00:00
Migrate more tests to html runner
Implement LocalStorage named get/set (i.e. localStorage["hi"])
This commit is contained in:
77
src/tests/url/url.html
Normal file
77
src/tests/url/url.html
Normal file
@@ -0,0 +1,77 @@
|
||||
<script src="../testing.js"></script>
|
||||
<script id=url>
|
||||
var url = new URL('https://foo.bar/path?query#fragment');
|
||||
testing.expectEqual("https://foo.bar", url.origin);
|
||||
testing.expectEqual("https://foo.bar/path?query#fragment", url.href);
|
||||
testing.expectEqual("https:", url.protocol);
|
||||
testing.expectEqual("", url.username);
|
||||
testing.expectEqual("", url.password);
|
||||
testing.expectEqual("foo.bar", url.host);
|
||||
testing.expectEqual("foo.bar", url.hostname);
|
||||
testing.expectEqual("", url.port);
|
||||
testing.expectEqual("/path", url.pathname);
|
||||
testing.expectEqual("?query", url.search);
|
||||
testing.expectEqual("#fragment", url.hash);
|
||||
testing.expectEqual("", url.searchParams.get('query'));
|
||||
|
||||
url.search = 'hello=world';
|
||||
testing.expectEqual(1, url.searchParams.size);
|
||||
testing.expectEqual("world", url.searchParams.get('hello'));
|
||||
|
||||
url.search = '?over=9000';
|
||||
testing.expectEqual(1, url.searchParams.size);
|
||||
testing.expectEqual("9000", url.searchParams.get('over'));
|
||||
|
||||
url.search = '';
|
||||
testing.expectEqual(0, url.searchParams.size);
|
||||
|
||||
const url2 = new URL(url);
|
||||
testing.expectEqual("https://foo.bar/path#fragment", url2.href);
|
||||
</script>
|
||||
|
||||
<script id="constructor">
|
||||
testing.expectError("TypeError: invalid argument", () => {
|
||||
new URL(document.createElement('a'));
|
||||
});
|
||||
|
||||
let a = document.createElement('a');
|
||||
a.href = 'https://www.lightpanda.io/over?9000=!!';
|
||||
const url3 = new URL(a);
|
||||
testing.expectEqual("https://www.lightpanda.io/over?9000=%21%21", url3.href);
|
||||
</script>
|
||||
|
||||
<script id=searchParams>
|
||||
url = new URL('https://foo.bar/path?a=~&b=%7E#fragment');
|
||||
testing.expectEqual("~", url.searchParams.get('a'));
|
||||
testing.expectEqual("~", url.searchParams.get('b'));
|
||||
|
||||
url.searchParams.append('c', 'foo');
|
||||
testing.expectEqual("foo", url.searchParams.get('c'));
|
||||
testing.expectEqual(1, url.searchParams.getAll('c').length);
|
||||
testing.expectEqual("foo", url.searchParams.getAll('c')[0]);
|
||||
testing.expectEqual(3, url.searchParams.size);
|
||||
|
||||
// search is dynamic
|
||||
testing.expectEqual("?a=~&b=~&c=foo", url.search);
|
||||
|
||||
// href is dynamic
|
||||
testing.expectEqual("https://foo.bar/path?a=~&b=~&c=foo#fragment", url.href);
|
||||
|
||||
url.searchParams.delete('c', 'foo');
|
||||
testing.expectEqual(null, url.searchParams.get('c'));
|
||||
url.searchParams.delete('a');
|
||||
testing.expectEqual(null, url.searchParams.get('a'));
|
||||
</script>
|
||||
|
||||
<script id=base>
|
||||
url = new URL('over?9000', 'https://lightpanda.io');
|
||||
testing.expectEqual("https://lightpanda.io/over?9000", url.href);
|
||||
</script>
|
||||
|
||||
<script id="svelkit">
|
||||
let sk = new URL('sveltekit-internal://');
|
||||
testing.expectEqual("sveltekit-internal:", sk.protocol);
|
||||
testing.expectEqual("", sk.host);
|
||||
testing.expectEqual("", sk.hostname);
|
||||
testing.expectEqual("sveltekit-internal://", sk.href);
|
||||
</script>
|
||||
93
src/tests/url/url_search_params.html
Normal file
93
src/tests/url/url_search_params.html
Normal file
@@ -0,0 +1,93 @@
|
||||
<script src="../testing.js"></script>
|
||||
<script id=url_search_params>
|
||||
let usp = new URLSearchParams();
|
||||
usp.get('a')
|
||||
testing.expectEqual(false, usp.has('a'));
|
||||
testing.expectEqual([], usp.getAll('a'));
|
||||
usp.delete('a');
|
||||
|
||||
usp.set('a', 1);
|
||||
testing.expectEqual(true, usp.has('a'));
|
||||
testing.expectEqual("1", usp.get('a'));
|
||||
testing.expectEqual(["1"], usp.getAll('a'));
|
||||
|
||||
usp.append('a', 2);
|
||||
testing.expectEqual(true, usp.has('a'));
|
||||
testing.expectEqual("1", usp.get('a'));
|
||||
testing.expectEqual(['1','2'], usp.getAll('a'));
|
||||
|
||||
usp.append('b', '3');
|
||||
testing.expectEqual(true, usp.has('a'));
|
||||
testing.expectEqual("1", usp.get('a'));
|
||||
testing.expectEqual(['1','2'], usp.getAll('a'));
|
||||
testing.expectEqual(true, usp.has('b'));
|
||||
testing.expectEqual("3", usp.get('b'));
|
||||
testing.expectEqual(['3'], usp.getAll('b'));
|
||||
|
||||
let acc = [];
|
||||
for (const key of usp.keys()) { acc.push(key) };
|
||||
testing.expectEqual(['a', 'a', 'b'], acc);
|
||||
|
||||
acc = [];
|
||||
for (const value of usp.values()) { acc.push(value) };
|
||||
testing.expectEqual(['1', '2', '3'], acc);
|
||||
|
||||
acc = [];
|
||||
for (const entry of usp.entries()) { acc.push(entry) };
|
||||
testing.expectEqual([['a', '1'], ['a', '2'], ['b', '3']], acc);
|
||||
|
||||
acc = [];
|
||||
for (const entry of usp) { acc.push(entry) };
|
||||
testing.expectEqual([['a', '1'], ['a', '2'], ['b', '3']], acc);
|
||||
|
||||
usp.delete('a');
|
||||
testing.expectEqual(false, usp.has('a'));
|
||||
testing.expectEqual(true, usp.has('b'));
|
||||
|
||||
acc = [];
|
||||
for (const key of usp.keys()) { acc.push(key) };
|
||||
testing.expectEqual(['b'], acc);
|
||||
|
||||
acc = [];
|
||||
for (const value of usp.values()) { acc.push(value) };
|
||||
testing.expectEqual(['3'], acc);
|
||||
|
||||
acc = [];
|
||||
for (const entry of usp.entries()) { acc.push(entry) };
|
||||
testing.expectEqual([['b', '3']], acc);
|
||||
|
||||
acc = [];
|
||||
for (const entry of usp) { acc.push(entry) };
|
||||
testing.expectEqual([['b', '3']], acc);
|
||||
</script>
|
||||
|
||||
<script id=parsed>
|
||||
usp = new URLSearchParams('?hello');
|
||||
testing.expectEqual('', usp.get('hello'));
|
||||
|
||||
usp = new URLSearchParams('?abc=');
|
||||
testing.expectEqual('', usp.get('abc'));
|
||||
|
||||
usp = new URLSearchParams('?abc=123&');
|
||||
testing.expectEqual('123', usp.get('abc'));
|
||||
testing.expectEqual(1, usp.size);
|
||||
|
||||
var fd = new FormData();
|
||||
fd.append('a', '1');
|
||||
fd.append('a', '2');
|
||||
fd.append('b', '3');
|
||||
ups = new URLSearchParams(fd);
|
||||
|
||||
testing.expectEqual(3, ups.size);
|
||||
testing.expectEqual(['1', '2'], ups.getAll('a'));
|
||||
|
||||
testing.expectEqual(['3'], ups.getAll('b'));
|
||||
|
||||
fd.delete('a'); // the two aren't linked, it created a copy
|
||||
testing.expectEqual(3, ups.size);
|
||||
|
||||
ups = new URLSearchParams({over: 9000, spice: 'flow'});
|
||||
testing.expectEqual(2, ups.size);
|
||||
testing.expectEqual(['9000'], ups.getAll('over'));
|
||||
testing.expectEqual(['flow'], ups.getAll('spice'));
|
||||
</script>
|
||||
Reference in New Issue
Block a user