mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-06-11 01:25:53 -04:00
140 lines
4.2 KiB
HTML
140 lines
4.2 KiB
HTML
<!DOCTYPE html>
|
|
<script src="../../testing.js"></script>
|
|
|
|
<link id="lh1" rel="stylesheet" href="/styles/main.css" media="screen" as="style" crossorigin="anonymous">
|
|
<link id="lh2">
|
|
|
|
<script id="link-from-html">
|
|
{
|
|
const lh1 = document.getElementById('lh1');
|
|
testing.expectEqual('HTMLLinkElement', lh1.constructor.name);
|
|
testing.expectEqual('stylesheet', lh1.rel);
|
|
testing.expectEqual(testing.ORIGIN + '/styles/main.css', lh1.href);
|
|
testing.expectEqual('screen', lh1.media);
|
|
testing.expectEqual('style', lh1.as);
|
|
testing.expectEqual('anonymous', lh1.crossOrigin);
|
|
|
|
lh1.rel = 'preload';
|
|
testing.expectEqual('preload', lh1.rel);
|
|
lh1.media = 'print';
|
|
testing.expectEqual('print', lh1.media);
|
|
|
|
const lh2 = document.getElementById('lh2');
|
|
testing.expectEqual('', lh2.rel);
|
|
testing.expectEqual('', lh2.href);
|
|
testing.expectEqual('', lh2.media);
|
|
testing.expectEqual('', lh2.as);
|
|
}
|
|
</script>
|
|
|
|
<script id=link>
|
|
let l2 = document.createElement('link');
|
|
testing.expectEqual('', l2.href);
|
|
l2.href = 'https://lightpanda.io/opensource-browser/15';
|
|
testing.expectEqual('https://lightpanda.io/opensource-browser/15', l2.href);
|
|
|
|
l2.href = '/over/9000';
|
|
testing.expectEqual(testing.ORIGIN + '/over/9000', l2.href);
|
|
|
|
l2.crossOrigin = 'nope';
|
|
testing.expectEqual('anonymous', l2.crossOrigin);
|
|
|
|
l2.crossOrigin = 'use-Credentials';
|
|
testing.expectEqual('use-credentials', l2.crossOrigin);
|
|
|
|
l2.crossOrigin = '';
|
|
testing.expectEqual('anonymous', l2.crossOrigin);
|
|
|
|
testing.expectEqual('', l2.media);
|
|
l2.media = 'screen and (max-width: 600px)';
|
|
testing.expectEqual('screen and (max-width: 600px)', l2.media);
|
|
l2.media = 'print';
|
|
testing.expectEqual('print', l2.media);
|
|
</script>
|
|
|
|
<script id="link-load-event">
|
|
{
|
|
// A link with rel=stylesheet and a non-empty href fires a load event when appended to the DOM
|
|
const link = document.createElement('link');
|
|
link.rel = 'stylesheet';
|
|
link.href = 'https://lightpanda.io/opensource-browser/15';
|
|
|
|
testing.async(async () => {
|
|
const result = await new Promise(resolve => {
|
|
link.addEventListener('load', ({ bubbles, cancelBubble, cancelable, composed, isTrusted, target }) => {
|
|
testing.expectEqual(false, bubbles);
|
|
testing.expectEqual(false, cancelBubble);
|
|
testing.expectEqual(false, cancelable);
|
|
testing.expectEqual(false, composed);
|
|
testing.expectEqual(true, isTrusted);
|
|
testing.expectEqual(link, target);
|
|
resolve(true);
|
|
});
|
|
document.head.appendChild(link);
|
|
});
|
|
testing.expectEqual(true, result);
|
|
});
|
|
testing.expectEqual(true, true);
|
|
}
|
|
</script>
|
|
|
|
<script id="link-no-load-without-href">
|
|
{
|
|
// A link with rel=stylesheet but no href should not fire a load event
|
|
let fired = false;
|
|
const link = document.createElement('link');
|
|
link.rel = 'stylesheet';
|
|
link.addEventListener('load', () => { fired = true; });
|
|
document.head.appendChild(link);
|
|
testing.onload(() => testing.expectEqual(false, fired));
|
|
}
|
|
</script>
|
|
|
|
<script id="link-no-load-wrong-rel">
|
|
{
|
|
// A link without rel=stylesheet should not fire a load event
|
|
let fired = false;
|
|
const link = document.createElement('link');
|
|
link.href = 'https://lightpanda.io/opensource-browser/15';
|
|
link.addEventListener('load', () => { fired = true; });
|
|
document.head.appendChild(link);
|
|
testing.onload(() => testing.expectEqual(false, fired));
|
|
}
|
|
</script>
|
|
|
|
<script id="lazy-href-set">
|
|
{
|
|
let result = false;
|
|
const link = document.createElement("link");
|
|
link.rel = "stylesheet";
|
|
link.onload = () => result = true;
|
|
// Append to DOM,
|
|
document.head.appendChild(link);
|
|
// then set href.
|
|
link.href = 'https://lightpanda.io/opensource-browser/15';
|
|
|
|
testing.onload(() => testing.expectEqual(true, result));
|
|
}
|
|
</script>
|
|
|
|
<script id="refs">
|
|
{
|
|
const rels = ['stylesheet', 'preload', 'modulepreload'];
|
|
const results = rels.map(() => false);
|
|
rels.forEach((rel, i) => {
|
|
let link = document.createElement('link')
|
|
link.rel = rel;
|
|
link.href = '/nope';
|
|
link.onload = () => results[i] = true;
|
|
document.documentElement.appendChild(link);
|
|
});
|
|
|
|
|
|
testing.onload(() => {
|
|
results.forEach((r) => {
|
|
testing.expectEqual(true, r);
|
|
});
|
|
});
|
|
}
|
|
</script>
|