tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

tex-image-with-invalid-data.html (5036B)


      1 <!--
      2 Copyright (c) 2019 The Khronos Group Inc.
      3 Use of this source code is governed by an MIT-style license that can be
      4 found in the LICENSE.txt file.
      5 -->
      6 <!DOCTYPE html>
      7 <html>
      8 <head>
      9 <meta charset="utf-8">
     10    <title>texImage2D and texSubImage2D tests with invalid data</title>
     11  <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
     12  <script src="../../../js/js-test-pre.js"></script>
     13  <script src="../../../js/webgl-test-utils.js"></script>
     14 </head>
     15 <body>
     16 <div id="description"></div>
     17 <div id="console"></div>
     18 <canvas id="canvas" width="2" height="2"> </canvas>
     19 <script type="application/javascript">
     20 description("texImage2D and texSubImage2D tests with invalid data");
     21 
     22 var wtu = WebGLTestUtils;
     23 var canvas = document.getElementById("canvas");
     24 var contextVersion = wtu.getDefault3DContextVersion();
     25 var gl = wtu.create3DContext(canvas);
     26 if (!gl)
     27  testFailed("Context created.");
     28 else
     29  testPassed("Context created.");
     30 
     31 var tex;
     32 
     33 function setup() {
     34    tex = gl.createTexture();
     35    gl.bindTexture(gl.TEXTURE_2D, tex);
     36    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
     37 }
     38 
     39 function teardown() {
     40    gl.deleteTexture(tex);
     41 }
     42 
     43 function test(desc, func, expected) {
     44    debug(desc);
     45 
     46    var exc = null;
     47    try {
     48        func();
     49    } catch (x) {
     50        exc = x;
     51    }
     52 
     53    if (expected == gl.INVALID_OPERATION) {
     54      wtu.glErrorShouldBe(gl, expected);
     55    } else if (expected == "exception") {
     56        if (exc) {
     57            testPassed("threw exception");
     58        } else {
     59            testFailed("did not throw exception");
     60        }
     61    }
     62 }
     63 
     64 test("Calling texImage2D with no WebGLTexture bound generates INVALID_OPERATION",
     65     function () {
     66        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
     67     },
     68     gl.INVALID_OPERATION);
     69 
     70 test("Calling texSubImage2D with no WebGLTexture bound generates INVALID_OPERATION",
     71     function () {
     72        var buffer = new Uint8Array(4);
     73        gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buffer);
     74     },
     75     gl.INVALID_OPERATION);
     76 
     77 setup();
     78 
     79 test("Passing a buffer not large enough to texImage2D should generate an INVALID_OPERATION",
     80     function () {
     81     var tooSmall = new Uint8Array(64);
     82        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, tooSmall);
     83     },
     84     gl.INVALID_OPERATION);
     85 
     86 if (contextVersion < 2) {
     87    test("Passing texImage2D parameter data of Number type should throw an exception",
     88         function () {
     89            gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, 42);
     90         },
     91         "exception");
     92 } else {
     93    test("Passing texImage2D parameter data of Number type should generate an INVALID_OPERATION",
     94         function () {
     95            gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, 42);
     96         },
     97         gl.INVALID_OPERATION);
     98 }
     99 
    100 if (contextVersion < 2) {
    101    test("Passing texImage2D parameter data of String type should throw a TypeError",
    102         function () {
    103            gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
    104         },
    105         "exception");
    106 } else {
    107    test("Passing texImage2D parameter data of String type should generate an INVALID_OPERATION",
    108         function () {
    109            gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
    110         },
    111         gl.INVALID_OPERATION);
    112 }
    113 
    114 test("Passing a buffer not large enough to texSubImage2D should generate an INVALID_OPERATION",
    115     function () {
    116        var tooSmall = new Uint8Array(64);
    117        gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, tooSmall);
    118     },
    119     gl.INVALID_OPERATION);
    120 
    121 if (contextVersion < 2) {
    122    test("Passing texSubImage2D parameter data of Number type should throw a TypeError",
    123         function () {
    124            gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, 42);
    125         },
    126         "exception");
    127 } else {
    128    test("Passing texSubImage2D parameter data of Number type should generate an INVALID_OPERATION",
    129         function () {
    130            gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, 42);
    131         },
    132         gl.INVALID_OPERATION);
    133 }
    134 
    135 if (contextVersion < 2) {
    136    test("Passing texSubImage2D parameter data of String type should throw a TypeError",
    137         function () {
    138            gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
    139         },
    140         "exception");
    141 } else {
    142    test("Passing texSubImage2D parameter data of String type should generate an INVALID_OPERATION",
    143         function () {
    144            gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
    145         },
    146         gl.INVALID_OPERATION);
    147 }
    148 
    149 teardown();
    150 
    151 debug("");
    152 var successfullyParsed = true;
    153 </script>
    154 <script src="../../../js/js-test-post.js"></script>
    155 
    156 </body>
    157 </html>