tor-browser

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

bad-arguments-test.html (3552B)


      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 
      7 <!DOCTYPE html>
      8 <html>
      9 <head>
     10 <meta charset="utf-8">
     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 
     19 <script>
     20 "use strict";
     21 var wtu = WebGLTestUtils;
     22 description("Tests calling WebGL APIs with wrong argument types");
     23 
     24 
     25 var testArguments = [
     26  { value: "foo",
     27    throwsForNullables: true },
     28  { value: 0,
     29    throwsForNullables: true },
     30  { value: null,
     31    throwsForNullables: false },
     32  { value: undefined,
     33    throwsForNullables: false }
     34 ];
     35 
     36 var argument;
     37 
     38 var context = wtu.create3DContext();
     39 var program;
     40 var shader;
     41 var loc;
     42 wtu.loadStandardProgramAsync(context, function(success, prog) {
     43  program = prog;
     44  wtu.loadStandardVertexShaderAsync(context, function(success, s) {
     45    shader = s;
     46 
     47    assertMsg(program != null, "Program Compiled");
     48    assertMsg(shader != null, "Shader Compiled");
     49 
     50    loc = context.getUniformLocation(program, "u_modelViewProjMatrix");
     51    assertMsg(loc != null, "getUniformLocation succeeded");
     52 
     53    for (var i = 0; i < testArguments.length; ++i) {
     54      argument = testArguments[i].value;
     55 
     56      debug('Testing argument: ' + argument);
     57 
     58      // These functions don't accept nullable arguments any more.
     59      shouldThrow("context.compileShader(argument)");
     60      shouldThrow("context.linkProgram(argument)");
     61      shouldThrow("context.attachShader(program, argument)");
     62      shouldThrow("context.attachShader(argument, shader)");
     63      shouldThrow("context.detachShader(program, argument)");
     64      shouldThrow("context.detachShader(argument, shader)");
     65      shouldThrow("context.shaderSource(argument, 'foo')");
     66      shouldThrow("context.bindAttribLocation(argument, 0, 'foo')");
     67      shouldThrow("context.getProgramInfoLog(argument)");
     68      shouldThrow("context.getProgramParameter(argument, 0)");
     69      shouldThrow("context.getShaderInfoLog(argument)");
     70      shouldThrow("context.getShaderParameter(argument, 0)");
     71      shouldThrow("context.getShaderSource(argument)");
     72      shouldThrow("context.getUniform(argument, loc)");
     73      shouldThrow("context.getUniform(program, argument)");
     74      shouldThrow("context.getUniformLocation(argument, 'u_modelViewProjMatrix')");
     75 
     76      // The following entry points still accept nullable arguments.
     77      var func;
     78      if (testArguments[i].throwsForNullables) {
     79        func = shouldThrow;
     80      } else {
     81        func = shouldBeUndefined;
     82      }
     83 
     84      func("context.bindBuffer(context.ARRAY_BUFFER, argument)");
     85      func("context.bindFramebuffer(context.FRAMEBUFFER, argument)");
     86      func("context.bindRenderbuffer(context.RENDERBUFFER, argument)");
     87      func("context.bindTexture(context.TEXTURE_2D, argument)");
     88      func("context.framebufferRenderbuffer(context.FRAMEBUFFER, context.DEPTH_ATTACHMENT, context.RENDERBUFFER, argument)");
     89      func("context.framebufferTexture2D(context.FRAMEBUFFER, context.COLOR_ATTACHMENT0, context.TEXTURE_2D, argument, 0)");
     90      func("context.uniform2fv(argument, new Float32Array([0.0, 0.0]))");
     91      func("context.uniform2iv(argument, new Int32Array([0, 0]))");
     92      func("context.uniformMatrix2fv(argument, false, new Float32Array([0.0, 0.0, 0.0, 0.0]))");
     93      func("context.useProgram(argument)");
     94    }
     95    finishTest();
     96  });
     97 });
     98 </script>
     99 </body>
    100 </html>