Merge pull request #1772 from lightpanda-io/nikneym/failing-body-onload-tests

Add failing `body.onload` tests
This commit is contained in:
Halil Durak
2026-03-15 10:58:39 +03:00
committed by GitHub
2 changed files with 35 additions and 7 deletions

View File

@@ -1,15 +1,15 @@
<!DOCTYPE html> <!DOCTYPE html>
<body onload="loaded()"></body> <body onload="loadEvent = event"></body>
<script src="../testing.js"></script> <script src="../testing.js"></script>
<script id=bodyOnLoad2> <script id=bodyOnLoad2>
let called = 0; // Per spec, the handler is compiled as: function(event) { loadEvent = event }
function loaded(e) { // Verify: handler fires, "event" parameter is a proper Event, and handler is a function.
called += 1; let loadEvent = null;
}
testing.eventually(() => { testing.eventually(() => {
testing.expectEqual(1, called); testing.expectEqual("function", typeof document.body.onload);
testing.expectTrue(loadEvent instanceof Event);
testing.expectEqual("load", loadEvent.type);
}); });
</script> </script>

View File

@@ -0,0 +1,28 @@
<!DOCTYPE html>
<body onload="called++"></body>
<script src="../testing.js"></script>
<script id=bodyOnLoad3>
// Per spec, the handler is compiled as: function(event) { called++ }
// Verify: handler fires exactly once, and body.onload reflects to window.onload.
let called = 0;
testing.eventually(() => {
// The attribute handler should have fired exactly once.
testing.expectEqual(1, called);
// body.onload is a Window-reflecting handler per spec.
testing.expectEqual("function", typeof document.body.onload);
testing.expectEqual(document.body.onload, window.onload);
// Setting body.onload via property replaces the attribute handler.
let propertyCalled = false;
document.body.onload = function() { propertyCalled = true; };
testing.expectEqual(document.body.onload, window.onload);
// Setting onload to null removes the handler.
document.body.onload = null;
testing.expectEqual(null, document.body.onload);
testing.expectEqual(null, window.onload);
});
</script>