add failing body.onload tests

This commit is contained in:
Halil Durak committed 2026-03-13 17:23:26 +03:00
1 parent be8ba53263
commit 8b310ce993
2 files changed
+35 -7

No files matched your search

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