<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(function(t) {
if (window.internals) {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.addEventListener('contextlost', t.step_func(() => {
contextLost(ctx);
}));
canvas.addEventListener('contextrestored', t.step_func_done(() => {
contextRestored(ctx);
}));
document.body.appendChild(ctx.canvas);
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>