blob: 71379f7d8c5bba8b2c90470d7c717f4b307db918 [file]
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="initial-scale=1">
<title>Tab Switch Canvas 2D Test: Diagonally opposite green and blue box, over red box</title>
<style type="text/css">
.nomargin {
margin: 0px auto;
}
</style>
<script>
let g_initialFramesBeforeReady = 2;
let g_swapsBeforeAck = 15;
let g_canvas;
let g_c2d;
let g_ready = false;
let g_hasHidden = false;
let g_waitingForFinish = false;
let g_finished = false;
// We manually send heartbeats during the requestAnimationFrame loops because
// the test harness only auto-wraps WebGL context methods, and there are no
// function calls here that can be easily wrapped without affecting tests whose
// requestAnimationFrame loops continue running after test completion.
// TODO(crbug.com/590200901): Remove this once requestAnimationFrame is properly
// wrapped with heartbeats.
function sendHeartbeat() {
if (!g_finished && window.wrapper) {
window.wrapper.sendHeartbeatThrottled();
}
}
function waitForInitialComposite() {
if (g_finished) {
return;
}
if (g_initialFramesBeforeReady == 0) {
g_ready = true;
sendResult("READY");
} else {
sendHeartbeat();
g_initialFramesBeforeReady--;
window.requestAnimationFrame(waitForInitialComposite);
}
}
function waitForFinish() {
if (g_finished) {
return;
}
if (g_swapsBeforeAck == 0) {
g_finished = true;
sendResult("SUCCESS");
} else {
sendHeartbeat();
g_swapsBeforeAck--;
window.requestAnimationFrame(waitForFinish);
}
}
function handleVisibilityChange() {
if (g_finished || !g_ready) {
return;
}
if (document.visibilityState == "visible") {
if (g_hasHidden && !g_waitingForFinish) {
g_waitingForFinish = true;
waitForFinish();
}
} else if (!g_hasHidden) {
g_hasHidden = true;
sendResult("CONTINUE");
}
}
function sendResult(status) {
if (window.domAutomationController) {
domAutomationController.send(status);
} else {
console.log(status);
}
}
function main() {
document.addEventListener("visibilitychange", handleVisibilityChange, false);
g_canvas = document.getElementById("c");
g_c2d = g_canvas.getContext("2d");
g_c2d.clearRect(0, 0, g_canvas.width, g_canvas.height);
g_c2d.fillStyle = "red";
g_c2d.fillRect(0, 0, 100, 100);
// Verify that output doesn't get flipped vertically.
g_c2d.fillStyle = "green";
g_c2d.fillRect(0, 0, 50, 50);
g_c2d.fillStyle = "blue";
g_c2d.fillRect(50, 50, 50, 50);
waitForInitialComposite();
}
</script>
</head>
<body onload="main()" class="nomargin">
<canvas id="c" width="100" height="100" class="nomargin" style="background-color:black"></canvas>
</body>
</html>