content/canvas/test/webgl-conformance/extra/out-of-memory.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/test/webgl-conformance/extra/out-of-memory.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,92 @@
     1.4 +<!--
     1.5 +Copyright (c) 2009 The Chromium Authors. All rights reserved.
     1.6 +Use of this source code is governed by a BSD-style license that can be
     1.7 +found in the LICENSE file.
     1.8 +-->
     1.9 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    1.10 +  "http://www.w3.org/TR/html4/loose.dtd">
    1.11 +<html>
    1.12 +<head>
    1.13 +<meta charset="utf-8">
    1.14 +<title>WebGL Out Of Memory Test</title>
    1.15 +<link rel="stylesheet" href="../resources/js-test-style.css"/>
    1.16 +<script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
    1.17 +<script src="../resources/js-test-pre.js"></script>
    1.18 +<script src="../conformance/resources/webgl-test.js"></script>
    1.19 +</head>
    1.20 +<body>
    1.21 +<div id="description"></div>
    1.22 +<div id="console"></div>
    1.23 +<canvas id="canvas" width="2" height="2"> </canvas>
    1.24 +<script>
    1.25 +debug("This tests WebGL running out of memory.");
    1.26 +
    1.27 +debug("");
    1.28 +debug("Canvas.getContext");
    1.29 +
    1.30 +var gl = create3DContext(document.getElementById("canvas"));
    1.31 +if (!gl) {
    1.32 +  testFailed("context does not exist");
    1.33 +} else {
    1.34 +  testPassed("context exists");
    1.35 +
    1.36 +  debug("");
    1.37 +  debug("Allocating shaders.");
    1.38 +
    1.39 +  function makeBigShader() {
    1.40 +    var lines = [];
    1.41 +    var line = "// ";
    1.42 +    for (var ii = 0; ii < 1024; ++ii) {
    1.43 +      line += String.fromCharCode(48 + ii % 10);
    1.44 +    }
    1.45 +    for (var ii = 0; ii < 1024; ++ii) {
    1.46 +      lines[ii] = line;
    1.47 +    }
    1.48 +    var oneMB = lines.join();
    1.49 +    for (var ii = 0; ii < 64; ++ii) {
    1.50 +      lines[ii] = oneMB;
    1.51 +    }
    1.52 +    return lines.join("\n");
    1.53 +  }
    1.54 +
    1.55 +  var shaderSource = makeBigShader();
    1.56 +  debug("created " + Math.floor(shaderSource.length / 1024 / 1024) + "MB shader");
    1.57 +
    1.58 +  var intervalId;
    1.59 +  var count = 0;
    1.60 +
    1.61 +  function makeShader() {
    1.62 +    ++count;
    1.63 +    debug ("creating shader #" + count + " mem = " + Math.floor(shaderSource.length * count / 1024 / 1024) + "MB");
    1.64 +    var shader = gl.createShader(gl.VERTEX_SHADER);
    1.65 +    if (shader == null) {
    1.66 +      window.clearInterval(intervalId);
    1.67 +      testPassed("createShader returns null");  // not sure this is a passing
    1.68 +      finish();
    1.69 +    } else {
    1.70 +      gl.shaderSource(shader, shaderSource);
    1.71 +      var err = gl.getError();
    1.72 +      if (err != gl.NO_ERROR) {
    1.73 +        window.clearInterval(intervalId);
    1.74 +        assertMsg(err == gl.OUT_OF_MEMORY, "shaderSource returns OUT_OF_MEMORY");
    1.75 +        finish();
    1.76 +      }
    1.77 +    }
    1.78 +  }
    1.79 +
    1.80 +  intervalId = window.setInterval(makeShader, 1000/15);
    1.81 +}
    1.82 +
    1.83 +function finish() {
    1.84 +  debug("");
    1.85 +  successfullyParsed = true;
    1.86 +}
    1.87 +
    1.88 +</script>
    1.89 +<!-- <script>finishTest();</script> -->
    1.90 +
    1.91 +<script>
    1.92 +</script>
    1.93 +
    1.94 +</body>
    1.95 +</html>

mercurial