content/canvas/test/reftest/webgl-disable-test.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/test/reftest/webgl-disable-test.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,60 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html class="reftest-wait">
     1.6 +<head>
     1.7 +<meta charset="UTF-8">
     1.8 +
     1.9 +<script type="text/javascript" src="webgl-utils.js"></script>
    1.10 +<script type="text/javascript">
    1.11 +/* Disable Test
    1.12 + *
    1.13 + * If we succeed in getting a WebGL context, we will fill
    1.14 + * the canvas with red. If we fail to acquire a WebGL context,
    1.15 + * we will use Canvas2D to instead fill it with green.
    1.16 + *
    1.17 + * Note that this test differs from the others in that
    1.18 + * it will draw differently if it receives a WebGL context.
    1.19 + * Other tests are designed to fallback silently to Canvas2D.
    1.20 + *
    1.21 + * We use this test to assure that when we disable WebGL,
    1.22 + * WebGL does not function. This is trivially true for systems
    1.23 + * that don't support WebGL. This test is not viable for testing
    1.24 + * that WebGL works, as blocklisted systems will always draw green.
    1.25 + */
    1.26 +
    1.27 +"use strict";
    1.28 +
    1.29 +function renderGL(gl) {
    1.30 +  gl.clearColor(1.0, 0.0, 0.0, 1.0);
    1.31 +  gl.clear(gl.COLOR_BUFFER_BIT);
    1.32 +  gl.finish();
    1.33 +}
    1.34 +
    1.35 +function renderBackup(canvas) {
    1.36 +  var context = canvas.getContext("2d");
    1.37 +  context.fillStyle = "rgba(0, 255, 0, 1.0)";
    1.38 +  context.fillRect(0, 0, 256, 256);
    1.39 +}
    1.40 +
    1.41 +function runTest() {
    1.42 +  var canvas = document.getElementById("canvas");
    1.43 +  var gl = initGL(canvas);
    1.44 +
    1.45 +  if (gl)
    1.46 +    renderGL(gl);
    1.47 +  else
    1.48 +    renderBackup(canvas);
    1.49 +
    1.50 +  waitForComposite(testComplete);
    1.51 +}
    1.52 +
    1.53 +function testComplete() {
    1.54 +  document.documentElement.removeAttribute("class");
    1.55 +}
    1.56 +</script>
    1.57 +</head>
    1.58 +
    1.59 +<body onload="rAF(runTest);">
    1.60 +  <canvas id="canvas" width="256" height="256"></canvas>
    1.61 +</body>
    1.62 +
    1.63 +</html>

mercurial