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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!--
     2 Copyright (c) 2009 The Chromium Authors. All rights reserved.
     3 Use of this source code is governed by a BSD-style license that can be
     4 found in the LICENSE file.
     5 -->
     6 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
     7   "http://www.w3.org/TR/html4/loose.dtd">
     8 <html>
     9 <head>
    10 <meta charset="utf-8">
    11 <title>WebGL Out Of Memory Test</title>
    12 <link rel="stylesheet" href="../resources/js-test-style.css"/>
    13 <script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
    14 <script src="../resources/js-test-pre.js"></script>
    15 <script src="../conformance/resources/webgl-test.js"></script>
    16 </head>
    17 <body>
    18 <div id="description"></div>
    19 <div id="console"></div>
    20 <canvas id="canvas" width="2" height="2"> </canvas>
    21 <script>
    22 debug("This tests WebGL running out of memory.");
    24 debug("");
    25 debug("Canvas.getContext");
    27 var gl = create3DContext(document.getElementById("canvas"));
    28 if (!gl) {
    29   testFailed("context does not exist");
    30 } else {
    31   testPassed("context exists");
    33   debug("");
    34   debug("Allocating shaders.");
    36   function makeBigShader() {
    37     var lines = [];
    38     var line = "// ";
    39     for (var ii = 0; ii < 1024; ++ii) {
    40       line += String.fromCharCode(48 + ii % 10);
    41     }
    42     for (var ii = 0; ii < 1024; ++ii) {
    43       lines[ii] = line;
    44     }
    45     var oneMB = lines.join();
    46     for (var ii = 0; ii < 64; ++ii) {
    47       lines[ii] = oneMB;
    48     }
    49     return lines.join("\n");
    50   }
    52   var shaderSource = makeBigShader();
    53   debug("created " + Math.floor(shaderSource.length / 1024 / 1024) + "MB shader");
    55   var intervalId;
    56   var count = 0;
    58   function makeShader() {
    59     ++count;
    60     debug ("creating shader #" + count + " mem = " + Math.floor(shaderSource.length * count / 1024 / 1024) + "MB");
    61     var shader = gl.createShader(gl.VERTEX_SHADER);
    62     if (shader == null) {
    63       window.clearInterval(intervalId);
    64       testPassed("createShader returns null");  // not sure this is a passing
    65       finish();
    66     } else {
    67       gl.shaderSource(shader, shaderSource);
    68       var err = gl.getError();
    69       if (err != gl.NO_ERROR) {
    70         window.clearInterval(intervalId);
    71         assertMsg(err == gl.OUT_OF_MEMORY, "shaderSource returns OUT_OF_MEMORY");
    72         finish();
    73       }
    74     }
    75   }
    77   intervalId = window.setInterval(makeShader, 1000/15);
    78 }
    80 function finish() {
    81   debug("");
    82   successfullyParsed = true;
    83 }
    85 </script>
    86 <!-- <script>finishTest();</script> -->
    88 <script>
    89 </script>
    91 </body>
    92 </html>

mercurial