chromium/third_party/blink/web_tests/fast/canvas/offscreencanvas-lost-gpu-context.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) {
        try {
            const canvas = new OffscreenCanvas(500, 500);
            const ctx = canvas.getContext('2d');
            canvas.addEventListener('contextlost', t.step_func(() => {
                contextLost(ctx);
            }));
            canvas.addEventListener('contextrestored', 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);
        } catch (e) {
            if (e instanceof RangeError) {
                // Due to the test infrastructure, it sometimes throws
                // "Uncaught RangeError: Maximum call stack size exceeded."
                // this shouldn't throw, but it shouldn't matter here if it does.
                // Do nothing.
            } else {
                throw e;
            }
        }
    } else {
        assert_true(false, "This test requires window.internals.");
    }
}, "Test the behavior of disconneced canvas recovery after a gpu context loss");
</script>
</body>
</html>