mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
update Image and Style tests
This commit is contained in:
@@ -114,62 +114,54 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id="load-trigger-event">
|
||||
{
|
||||
const img = document.createElement("img");
|
||||
let count = 0;
|
||||
img.addEventListener("load", ({ bubbles, cancelBubble, cancelable, composed, isTrusted, target }) => {
|
||||
testing.expectEqual(true, count < 3);
|
||||
count++;
|
||||
<body></body>
|
||||
|
||||
<script id="img-load-event">
|
||||
{
|
||||
// An img fires a load event when src is set.
|
||||
const img = document.createElement("img");
|
||||
let result = false;
|
||||
testing.async(async () => {
|
||||
await new Promise(resolve => {
|
||||
img.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(img, target);
|
||||
result = true;
|
||||
return resolve();
|
||||
});
|
||||
img.src = "https://cdn.lightpanda.io/website/assets/images/docs/hn.png";
|
||||
});
|
||||
});
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
img.src = "https://cdn.lightpanda.io/website/assets/images/docs/hn.png";
|
||||
testing.expectEqual("https://cdn.lightpanda.io/website/assets/images/docs/hn.png", img.src);
|
||||
}
|
||||
|
||||
// Make sure count is incremented asynchronously.
|
||||
testing.expectEqual(0, count);
|
||||
testing.eventually(() => testing.expectEqual(true, result));
|
||||
}
|
||||
</script>
|
||||
|
||||
<img
|
||||
id="inline-img"
|
||||
src="https://cdn.lightpanda.io/website/assets/images/docs/hn.png"
|
||||
onload="(() => testing.expectEqual(true, true))()"
|
||||
/>
|
||||
|
||||
<script id="inline-on-load">
|
||||
<script id="img-no-load-without-src">
|
||||
{
|
||||
const img = document.getElementById("inline-img");
|
||||
testing.expectEqual(true, img.onload instanceof Function);
|
||||
// Also call inline to double check.
|
||||
img.onload();
|
||||
// An img without src should not fire a load event.
|
||||
let fired = false;
|
||||
const img = document.createElement("img");
|
||||
img.addEventListener("load", () => { fired = true; });
|
||||
document.body.appendChild(img);
|
||||
testing.eventually(() => testing.expectEqual(false, fired));
|
||||
}
|
||||
</script>
|
||||
|
||||
// Make sure ones attached with `addEventListener` also executed.
|
||||
testing.async(async () => {
|
||||
const result = await new Promise(resolve => {
|
||||
img.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(img, target);
|
||||
<script id="lazy-src-set">
|
||||
{
|
||||
// Append to DOM first, then set src — load should still fire.
|
||||
const img = document.createElement("img");
|
||||
let result = false;
|
||||
img.onload = () => result = true;
|
||||
document.body.appendChild(img);
|
||||
img.src = "https://cdn.lightpanda.io/website/assets/images/docs/hn.png";
|
||||
|
||||
return resolve(true);
|
||||
});
|
||||
});
|
||||
|
||||
testing.expectEqual(true, result);
|
||||
});
|
||||
testing.eventually(() => testing.expectEqual(true, result));
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -106,3 +106,28 @@
|
||||
testing.expectEqual(true, style.disabled);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id="style-load-event">
|
||||
{
|
||||
// A style element fires a load event when appended to the DOM.
|
||||
const style = document.createElement("style");
|
||||
let result = false;
|
||||
testing.async(async () => {
|
||||
await new Promise(resolve => {
|
||||
style.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(style, target);
|
||||
result = true;
|
||||
return resolve();
|
||||
});
|
||||
document.head.appendChild(style);
|
||||
});
|
||||
});
|
||||
|
||||
testing.eventually(() => testing.expectEqual(true, result));
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user