tor-browser

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

instanceof-test.js (3721B)


      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 var wtu = WebGLTestUtils;
     13 description(document.title);
     14 debug("Tests that instanceof works on WebGL objects.");
     15 debug("");
     16 
     17 function checkGLError(message) {
     18  var error = gl.getError();
     19  if (error != gl.NO_ERROR) {
     20    wtu.error("Error: " + message + " caused " + wtu.glEnumToString(gl, error));
     21  }
     22 }
     23 
     24 var gl = wtu.create3DContext("canvas", undefined, contextVersion);
     25 if (contextVersion === 1) {
     26  shouldBeTrue('gl instanceof WebGLRenderingContext');
     27 } else if (contextVersion === 2) {
     28  shouldBeTrue('gl instanceof WebGL2RenderingContext');
     29 }
     30 
     31 shouldBeTrue('gl.createBuffer() instanceof WebGLBuffer');
     32 checkGLError("createBuffer")
     33 
     34 shouldBeTrue('gl.createFramebuffer() instanceof WebGLFramebuffer');
     35 checkGLError("createFramebuffer")
     36 
     37 shouldBeTrue('gl.createProgram() instanceof WebGLProgram');
     38 checkGLError("createProgram")
     39 
     40 shouldBeTrue('gl.createRenderbuffer() instanceof WebGLRenderbuffer');
     41 checkGLError("createRenderbuffer")
     42 
     43 shouldBeTrue('gl.createShader(gl.VERTEX_SHADER) instanceof WebGLShader');
     44 checkGLError("createShader")
     45 
     46 shouldBeTrue('gl.createTexture() instanceof WebGLTexture');
     47 checkGLError("createTexture")
     48 
     49 if (contextVersion > 1) {
     50  shouldBeTrue('gl.createQuery() instanceof WebGLQuery');
     51  checkGLError("createQuery")
     52 
     53  shouldBeTrue('gl.createSampler() instanceof WebGLSampler');
     54  checkGLError("createSampler")
     55 
     56  shouldBeTrue('gl.createTransformFeedback() instanceof WebGLTransformFeedback');
     57  checkGLError("createTransformFeedback")
     58 
     59  shouldBeTrue('gl.createVertexArray() instanceof WebGLVertexArrayObject');
     60  checkGLError("createVertexArray")
     61 }
     62 
     63 var program = wtu.setupProgram(gl, ['vshader', 'fshader'], ['vPosition'], [0]);
     64 
     65 shouldBeTrue('gl.getUniformLocation(program, "color") instanceof WebGLUniformLocation');
     66 checkGLError("getUniformLocation")
     67 
     68 shouldBeTrue('gl.getActiveAttrib(program, 0) instanceof WebGLActiveInfo');
     69 checkGLError("getActiveAttrib")
     70 
     71 shouldBeTrue('gl.getActiveUniform(program, 0) instanceof WebGLActiveInfo');
     72 checkGLError("getActiveUniform")
     73 
     74 debug("");
     75 debug("Tests that those WebGL objects can not be constructed through new operator");
     76 debug("");
     77 
     78 function shouldThrowWithNew(objectType, objectName) {
     79  try {
     80    new objectType;
     81    testFailed('new ' + objectName + ' did not throw');
     82  } catch (e) {
     83    testPassed('new ' + objectName + ' threw an error');
     84  }
     85 }
     86 
     87 shouldThrowWithNew(window.WebGLRenderingContext, 'WebGLRenderingContext');
     88 shouldThrowWithNew(window.WebGLActiveInfo, 'WebGLActiveInfo');
     89 shouldThrowWithNew(window.WebGLBuffer, 'WebGLBuffer');
     90 shouldThrowWithNew(window.WebGLFramebuffer, 'WebGLFramebuffer');
     91 shouldThrowWithNew(window.WebGLProgram, 'WebGLProgram');
     92 shouldThrowWithNew(window.WebGLRenderbuffer, 'WebGLRenderbuffer');
     93 shouldThrowWithNew(window.WebGLShader, 'WebGLShader');
     94 shouldThrowWithNew(window.WebGLTexture, 'WebGLTexture');
     95 shouldThrowWithNew(window.WebGLUniformLocation, 'WebGLUniformLocation');
     96 shouldThrowWithNew(window.WebGLShaderPrecisionFormat, 'WebGLShaderPrecisionFormat');
     97 if (contextVersion > 1) {
     98  shouldThrowWithNew(window.WebGLQuery, 'WebGLQuery');
     99  shouldThrowWithNew(window.WebGLSampler, 'WebGLSampler');
    100  shouldThrowWithNew(window.WebGLSync, 'WebGLSync');
    101  shouldThrowWithNew(window.WebGLTransformFeedback, 'WebGLTransformFeedback');
    102  shouldThrowWithNew(window.WebGLVertexArrayObject, 'WebGLVertexArrayObject');
    103 }
    104 
    105 var successfullyParsed = true;