tor-browser

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

gl-enum-tests.js (5255B)


      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 // This test relies on the surrounding web page defining a variable
      8 // "contextVersion" which indicates what version of WebGL it's running
      9 // on -- 1 for WebGL 1.0, 2 for WebGL 2.0, etc.
     10 
     11 "use strict";
     12 description("This test ensures various WebGL functions fail when passed invalid OpenGL ES enums.");
     13 
     14 debug("");
     15 debug("Canvas.getContext");
     16 
     17 var wtu = WebGLTestUtils;
     18 var gl = wtu.create3DContext("canvas", undefined, contextVersion);
     19 if (!gl) {
     20  testFailed("context does not exist");
     21 } else {
     22  testPassed("context exists");
     23 
     24  debug("");
     25  debug("Checking gl enums.");
     26 
     27  var buffer = new ArrayBuffer(2);
     28  var buf = new Uint16Array(buffer);
     29  var tex = gl.createTexture();
     30  var program = wtu.createProgram(gl, wtu.loadStandardVertexShader(gl), wtu.loadStandardFragmentShader(gl));
     31  gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
     32  wtu.glErrorShouldBe(gl, gl.NO_ERROR);
     33 
     34  var tests = [
     35    "gl.disable(desktopGL['CLIP_PLANE0'])",
     36    "gl.disable(desktopGL['POINT_SPRITE'])",
     37    "gl.getBufferParameter(gl.ARRAY_BUFFER, desktopGL['PIXEL_PACK_BUFFER'])",
     38    "gl.hint(desktopGL['PERSPECTIVE_CORRECTION_HINT'], gl.FASTEST)",
     39    "gl.isEnabled(desktopGL['CLIP_PLANE0'])",
     40    "gl.isEnabled(desktopGL['POINT_SPRITE'])",
     41    "gl.pixelStorei(desktopGL['PACK_SWAP_BYTES'], 1)",
     42    "gl.getParameter(desktopGL['NUM_COMPRESSED_TEXTURE_FORMATS'])",
     43    "gl.getParameter(desktopGL['EXTENSIONS'])",
     44    "gl.getParameter(desktopGL['SHADER_COMPILER'])",
     45    "gl.getParameter(desktopGL['SHADER_BINARY_FORMATS'])",
     46    "gl.getParameter(desktopGL['NUM_SHADER_BINARY_FORMATS'])",
     47  ];
     48 
     49  if (contextVersion < 2) {
     50    tests = tests.concat([
     51      "gl.blendEquation(desktopGL['MIN'])",
     52      "gl.blendEquation(desktopGL['MAX'])",
     53      "gl.blendEquationSeparate(desktopGL['MIN'], gl.FUNC_ADD)",
     54      "gl.blendEquationSeparate(desktopGL['MAX'], gl.FUNC_ADD)",
     55      "gl.blendEquationSeparate(gl.FUNC_ADD, desktopGL['MIN'])",
     56      "gl.blendEquationSeparate(gl.FUNC_ADD, desktopGL['MAX'])",
     57      "gl.bufferData(gl.ARRAY_BUFFER, 16, desktopGL['STREAM_READ'])",
     58      "gl.bufferData(gl.ARRAY_BUFFER, 16, desktopGL['STREAM_COPY'])",
     59      "gl.bufferData(gl.ARRAY_BUFFER, 16, desktopGL['STATIC_READ'])",
     60      "gl.bufferData(gl.ARRAY_BUFFER, 16, desktopGL['STATIC_COPY'])",
     61      "gl.bufferData(gl.ARRAY_BUFFER, 16, desktopGL['DYNAMIC_READ'])",
     62      "gl.bufferData(gl.ARRAY_BUFFER, 16, desktopGL['DYNAMIC_COPY'])",
     63      "gl.bindTexture(desktopGL['TEXTURE_2D_ARRAY'], tex)",
     64      "gl.bindTexture(desktopGL['TEXTURE_3D'], tex)",
     65    ]);
     66  } else {
     67    tests = tests.concat([
     68      "gl.bindTexture(desktopGL['TEXTURE_RECTANGLE_EXT'], tex)",
     69      "gl.enable(desktopGL['PRIMITIVE_RESTART_FIXED_INDEX'])",
     70      "gl.getActiveUniforms(program, [0], desktopGL['UNIFORM_NAME_LENGTH'])",
     71      "gl.getProgramParameter(program, desktopGL['ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH'])",
     72      "gl.getProgramParameter(program, desktopGL['TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH'])",
     73      "gl.getProgramParameter(program, desktopGL['PROGRAM_BINARY_RETRIEVABLE_HINT'])",
     74      "gl.getProgramParameter(program, desktopGL['PROGRAM_BINARY_LENGTH'])",
     75      "gl.getParameter(program, desktopGL['NUM_PROGRAM_BINARY_FORMATS'])",
     76    ]);
     77  }
     78 
     79  for (var ii = 0; ii < tests.length; ++ii) {
     80    TestEval(tests[ii]);
     81    wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, tests[ii] + " should return INVALID_ENUM.");
     82  }
     83 
     84  gl.bindTexture(gl.TEXTURE_2D, tex);
     85  wtu.glErrorShouldBe(gl, gl.NO_ERROR);
     86 
     87  tests = [
     88    "gl.getTexParameter(gl.TEXTURE_2D, desktopGL['GENERATE_MIPMAP'])",
     89    "gl.texParameteri(gl.TEXTURE_2D, desktopGL['GENERATE_MIPMAP'], 1)",
     90    "gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, desktopGL['CLAMP_TO_BORDER'])",
     91  ];
     92 
     93  if (contextVersion < 2) {
     94    tests = tests.concat([
     95      "gl.texParameteri(desktopGL['TEXTURE_2D_ARRAY'], gl.TEXTURE_MAG_FILTER, gl.NEAREST)",
     96      "gl.texParameteri(desktopGL['TEXTURE_3D'], gl.TEXTURE_MAG_FILTER, gl.NEAREST)",
     97    ]);
     98  } else {
     99    tests = tests.concat([
    100      "gl.texParameteri(desktopGL['TEXTURE_2D'], desktopGL['TEXTURE_SWIZZLE_R_EXT'], gl.RED)",
    101      "gl.texParameteri(desktopGL['TEXTURE_2D'], desktopGL['TEXTURE_SWIZZLE_G_EXT'], gl.RED)",
    102      "gl.texParameteri(desktopGL['TEXTURE_2D'], desktopGL['TEXTURE_SWIZZLE_B_EXT'], gl.RED)",
    103      "gl.texParameteri(desktopGL['TEXTURE_2D'], desktopGL['TEXTURE_SWIZZLE_A_EXT'], gl.RED)",
    104      "gl.texParameteri(desktopGL['TEXTURE_2D'], gl.TEXTURE_WRAP_R, desktopGL['CLAMP_TO_BORDER'])",
    105    ]);
    106  }
    107 
    108  for (var ii = 0; ii < tests.length; ++ii) {
    109    TestEval(tests[ii]);
    110    wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, tests[ii] + " should return INVALID_ENUM.");
    111  }
    112  if (contextVersion >= 2) {
    113    var uniformBlockProgram = wtu.loadUniformBlockProgram(gl);
    114    gl.linkProgram(uniformBlockProgram);
    115    shouldBe('gl.getProgramParameter(uniformBlockProgram, gl.LINK_STATUS)', 'true');
    116    shouldBe('gl.getError()', 'gl.NO_ERROR');
    117    gl.getActiveUniformBlockParameter(uniformBlockProgram, 0, desktopGL['UNIFORM_BLOCK_NAME_LENGTH']);
    118    shouldBe('gl.getError()', 'gl.INVALID_ENUM');
    119  }
    120 }
    121 
    122 debug("");
    123 var successfullyParsed = true;