Skip to content

Truly independent web browser

1.6 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<script src="frame-in-flight.js"></script>
<style>
    #box { width: 50px; height: 10px; }
</style>
<div id="box"></div>
<script>
    // A task beside a frame in flight that writes and then reads in the same task: the read waits for the frame, and
    // sees the write. So does a script that creates a scroll timeline.
    asyncTest(async done => {
        const result = await whileRecordingInFlight(() => {
            box.style.height = "12px";
        }, state => {
            box.style.width = "70px";
            const width = getComputedStyle(box).width;
            return { state, width, afterRead: internals.frameSchedulerState(), offsetWidth: box.offsetWidth };
        });
        println(`state next task: ${result.state}`);
        println(`read beside the frame: ${result.width}, ${result.offsetWidth}`);
        println(`state after the read: ${result.afterRead}`);
        await twoFrames();
        println(`box: ${box.offsetWidth}x${box.offsetHeight}`);

        // A new scroll timeline reads its current time from the boxes, which waits for the frame too.
        const timeline = await whileRecordingInFlight(() => {
            box.style.height = "14px";
        }, state => {
            const timeline = new ScrollTimeline({ source: document.scrollingElement });
            return { state, afterRead: internals.frameSchedulerState(), currentTime: timeline.currentTime };
        });
        println(`scroll timeline: state next task: ${timeline.state}, after: ${timeline.afterRead}, current time: ${timeline.currentTime}`);
        done();
    });
</script>