mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 14:43:28 +00:00
168 lines
4.7 KiB
HTML
168 lines
4.7 KiB
HTML
<!DOCTYPE html>
|
|
<script src="../testing.js"></script>
|
|
<body style=height:4000px;width:4000px></body>
|
|
<script id=aliases>
|
|
testing.expectEqual(window, window.self);
|
|
testing.expectEqual(window, window.parent);
|
|
testing.expectEqual(window, window.top);
|
|
testing.expectEqual(window, window.frames);
|
|
testing.expectEqual(0, window.frames.length);
|
|
</script>
|
|
|
|
<script id=request_animation>
|
|
let start = 0;
|
|
function step(timestamp) {
|
|
start = timestamp;
|
|
}
|
|
requestAnimationFrame(step);
|
|
testing.eventually(() => testing.expectEqual(true, start > 0));
|
|
|
|
let request_id = requestAnimationFrame(() => {
|
|
start = 0;
|
|
});
|
|
cancelAnimationFrame(request_id);
|
|
testing.eventually(() => testing.expectEqual(true, start > 0));
|
|
</script>
|
|
|
|
<script id=dimensions>
|
|
testing.expectEqual(5, innerHeight);
|
|
// Width is 5 even if there are no elements
|
|
testing.expectEqual(5, innerWidth);
|
|
|
|
let div1 = document.createElement('div');
|
|
document.body.appendChild(div1);
|
|
div1.getClientRects()
|
|
|
|
let div2 = document.createElement('div');
|
|
document.body.appendChild(div2);
|
|
div2.getClientRects();
|
|
|
|
testing.expectEqual(5, innerHeight);
|
|
testing.expectEqual(10, innerWidth);
|
|
</script>
|
|
|
|
<script id=setTimeout>
|
|
let longCall = false;
|
|
window.setTimeout(() => {longCall = true}, 5001);
|
|
testing.eventually(() => testing.expectEqual(false, longCall));
|
|
|
|
let wst1 = 0;
|
|
window.setTimeout(() => {wst1 += 1}, 1);
|
|
testing.eventually(() => testing.expectEqual(1, wst1));
|
|
|
|
let wst2 = 1;
|
|
window.setTimeout((a, b) => {wst2 = a + b}, 1, 2, 3);
|
|
testing.eventually(() => testing.expectEqual(5, wst2));
|
|
</script>
|
|
|
|
<script id=eventTarget>
|
|
let called = false;
|
|
|
|
window.addEventListener("ready", (e) => {
|
|
called = (e.currentTarget == window);
|
|
}, {capture: false, once: false});
|
|
|
|
const evt = new Event("ready", { bubbles: true, cancelable: false });
|
|
window.dispatchEvent(evt);
|
|
testing.expectEqual(true, called);
|
|
</script>
|
|
|
|
<script id=btoa_atob>
|
|
const b64 = btoa('https://ziglang.org/documentation/master/std/#std.base64.Base64Decoder')
|
|
testing.expectEqual('aHR0cHM6Ly96aWdsYW5nLm9yZy9kb2N1bWVudGF0aW9uL21hc3Rlci9zdGQvI3N0ZC5iYXNlNjQuQmFzZTY0RGVjb2Rlcg==', b64);
|
|
|
|
const str = atob(b64)
|
|
testing.expectEqual('https://ziglang.org/documentation/master/std/#std.base64.Base64Decoder', str);
|
|
|
|
testing.expectError('Error: InvalidCharacterError', () => {
|
|
atob('b');
|
|
});
|
|
</script>
|
|
|
|
<script id=scroll>
|
|
let scroll = false;
|
|
let scrollend = false
|
|
|
|
window.addEventListener('scroll', () => {scroll = true});
|
|
document.addEventListener('scrollend', () => {scrollend = true});
|
|
window.scrollTo(0, 0);
|
|
testing.expectEqual(0, scrollX);
|
|
testing.expectEqual(0, pageXOffset);
|
|
testing.expectEqual(0, scrollY);
|
|
testing.expectEqual(0, pageYOffset);
|
|
|
|
testing.expectEqual(true, scroll);
|
|
testing.expectEqual(true, scrollend);
|
|
|
|
window.scrollTo(10, 20);
|
|
testing.expectEqual(10, scrollX);
|
|
testing.expectEqual(10, pageXOffset);
|
|
testing.expectEqual(20, scrollY);
|
|
testing.expectEqual(20, pageYOffset);
|
|
|
|
window.scrollTo(-10, -20);
|
|
testing.expectEqual(0, scrollX);
|
|
testing.expectEqual(0, pageXOffset);
|
|
testing.expectEqual(0, scrollY);
|
|
testing.expectEqual(0, pageYOffset);
|
|
|
|
window.scrollTo({top: 30, left: 40});
|
|
testing.expectEqual(40, scrollX);
|
|
testing.expectEqual(40, pageXOffset);
|
|
testing.expectEqual(30, scrollY);
|
|
testing.expectEqual(30, pageYOffset);
|
|
|
|
window.scrollTo({top: -30, left: -40});
|
|
testing.expectEqual(0, scrollX);
|
|
testing.expectEqual(0, pageXOffset);
|
|
testing.expectEqual(0, scrollY);
|
|
testing.expectEqual(0, pageYOffset);
|
|
</script>
|
|
|
|
<script id=queueMicroTask>
|
|
var qm = false;
|
|
window.queueMicrotask(() => {qm = true });
|
|
testing.eventually(() => testing.expectEqual(true, qm));
|
|
</script>
|
|
|
|
<script id=DOMContentLoaded>
|
|
let dcl = false;
|
|
window.queueMicrotask(() => {qm = true });
|
|
window.addEventListener('DOMContentLoaded', (e) => {
|
|
dcl = e.target == document;
|
|
});
|
|
testing.eventually(() => testing.expectEqual(true, dcl));
|
|
</script>
|
|
|
|
<script id=window.onload>
|
|
let isWindowTarget = false;
|
|
|
|
const callback = (e) => isWindowTarget = e.target === window;
|
|
// Callback is not set yet.
|
|
testing.expectEqual(null, window.onload);
|
|
// Setting an object.
|
|
window.onload = {};
|
|
testing.expectEqual(null, window.onload);
|
|
// Callback is set.
|
|
window.onload = callback;
|
|
testing.expectEqual(callback, window.onload);
|
|
|
|
testing.eventually(() => testing.expectEqual(true, isWindowTarget));
|
|
</script>
|
|
|
|
<script id=reportError>
|
|
let errorEventFired = false;
|
|
let capturedError = null;
|
|
|
|
window.addEventListener('error', (e) => {
|
|
errorEventFired = true;
|
|
capturedError = e.error;
|
|
});
|
|
|
|
const testError = new Error('Test error message');
|
|
window.reportError(testError);
|
|
|
|
testing.expectEqual(true, errorEventFired);
|
|
testing.expectEqual(testError, capturedError);
|
|
</script>
|