chromium/third_party/blink/web_tests/fast/canvas/offscreencanvas-oncontextlost.html

<html>
<head>
<script src="../../resources/js-test.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="resources/canvas-context-lost-events.js"></script>
</head>
<body>
<script>
async_test(t => {
    if (window.internals) {
        const canvas = new OffscreenCanvas(500, 500);
        const ctx = canvas.getContext('2d');
        canvas.oncontextlost = t.step_func(() => {
            contextLost(ctx);
        });
        canvas.oncontextrestored = t.step_func_done(() => {
            contextRestored(ctx);
        });

        ctx.fillRect(0, 0, 1, 1);
        // setTimeout creates a frame barrier that locks the canvas into gpu
        // acceleration mode when running under virtual/gpu
        t.step_timeout(() => {
            // Now it is safe to use verifyContextLost without fearing side-effects
            // because a rendering mode was fixed.
            verifyContextLost(false, ctx);

            internals.forceLoseCanvasContext(canvas, "2d");
            if (!ctx.isContextLost()) {
                assert_true(false, "canvas context is not lost properly.");
            } else {
                verifyContextLost(true, ctx);
            }
        }, 0);
    } else {
        assert_true(false, "This test requires window.internals.");
    }
}, "Test the behavior of disconneced canvas recovery after a gpu context loss");
</script>
</body>
</html>