blob: 5618262f69c077d8de7741357cc4f828dece4460 [file]
<!--
Regression test for crbug.com/361553 / crbug.com/41101884: toggling
fullscreen on a page with a WebGL context must not lose the context.
-->
<html>
<head>
<script type="text/javascript">
var gl;
var contextWasLost = false;
var enteredFullscreen = false;
var fullscreenRequestFailed = false;
function contextLostHandler() {
contextWasLost = true;
}
function fullscreenChangeHandler() {
if (document.fullscreenElement) {
// The canvas just entered fullscreen. Immediately exit to exercise the
// full enter/exit cycle.
enteredFullscreen = true;
document.exitFullscreen();
return;
}
// The canvas just exited fullscreen, so the test is finished.
if (!enteredFullscreen) {
console.error("fullscreenchange fired without entering fullscreen");
window.domAutomationController.send("FAILED");
} else if (contextWasLost) {
console.error("WebGL context was lost during fullscreen transition");
window.domAutomationController.send("FAILED");
} else {
window.domAutomationController.send("SUCCESS");
}
}
function enterFullscreen() {
fullscreenRequestFailed = false;
var canvas = document.getElementById("canvas1");
var promise = canvas.requestFullscreen();
if (promise && promise.catch) {
promise.catch(function(err) {
console.error("requestFullscreen failed:", err);
fullscreenRequestFailed = true;
});
}
}
function onLoad() {
window.domAutomationController.send("LOADED");
var canvas = document.getElementById("canvas1");
if (!canvas) {
window.domAutomationController.send("FAILED");
return;
}
canvas.addEventListener("webglcontextlost", contextLostHandler, false);
document.addEventListener("fullscreenchange", fullscreenChangeHandler, false);
gl = canvas.getContext("webgl");
if (!gl) {
window.domAutomationController.send("FAILED");
return;
}
// Render a frame so the context is actually created and used.
gl.clearColor(0, 1, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
}
</script>
</head>
<body onload="onLoad()">
<button id="enterFullscreenButton" onclick="enterFullscreen()">
Enter fullscreen
</button>
<canvas id="canvas1" width="32px" height="32px">
</canvas>
</body>
</html>