tor-browser

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

test_uninit_data.html (2503B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta http-equiv='content-type' content='text/html; charset=utf-8'/>
      5 
      6  <title>Test contents of uninitialized buffers</title>
      7 
      8  <script src='/tests/SimpleTest/SimpleTest.js'></script>
      9  <link rel='stylesheet' href='/tests/SimpleTest/test.css'>
     10  <script src='webgl-util.js'></script>
     11 </head>
     12 
     13 <body>
     14 <script>
     15 'use strict';
     16 
     17 function TestFB(gl) {
     18  var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
     19  ok(status == gl.FRAMEBUFFER_COMPLETE, 'FB should be complete.');
     20 
     21  var pixel = new Uint8Array(4);
     22  gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
     23 
     24  ok(!pixel[0], 'R channel should be 0, was ' + pixel[0] + '.');
     25  ok(!pixel[1], 'G channel should be 0, was ' + pixel[1] + '.');
     26  ok(!pixel[2], 'B channel should be 0, was ' + pixel[2] + '.');
     27  ok(!pixel[3], 'A channel should be 0, was ' + pixel[3] + '.');
     28 }
     29 
     30 function Test(contextAttribs) {
     31  ok(true, '===============================');
     32  ok(true, 'Testing ' + JSON.stringify(contextAttribs));
     33 
     34  var c = document.createElement('canvas');
     35  var gl = c.getContext('webgl', contextAttribs);
     36  if (!gl) {
     37    todo(false, 'WebGL is unavailable.');
     38    return;
     39  }
     40 
     41  var rb = gl.createRenderbuffer();
     42  gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
     43 
     44  var tex = gl.createTexture();
     45  gl.bindTexture(gl.TEXTURE_2D, tex);
     46 
     47  var err = gl.getError();
     48  ok(!err, 'Error should be 0x0, was 0x' + err.toString(16));
     49  if (err)
     50    return;
     51 
     52  var fb = gl.createFramebuffer();
     53  gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
     54 
     55  ok(true, 'Backed with RB');
     56  gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb);
     57  gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 1, 1);
     58  TestFB(gl);
     59 
     60  ok(true, 'Backed with texture');
     61  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
     62  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
     63  TestFB(gl);
     64 
     65  err = gl.getError();
     66  ok(!err, 'Error should be 0x0, was 0x' + err.toString(16));
     67 }
     68 
     69 // Give ourselves a scope to return early from:
     70 (function() {
     71  // We test multiple configurations because we've had bugs regarding faking RGBX on
     72  // ANGLE: With alpha:false, uninitialized buffers were being filled with (0,0,0,1)
     73  // instead of (0,0,0,0).
     74  Test({alpha: false, antialias: false});
     75  Test({alpha: true, antialias: false});
     76  Test({alpha: false, antialias: true});
     77  Test({alpha: true, antialias: true});
     78 
     79  ok(true, 'Test complete.');
     80 })();
     81 
     82 </script>
     83 </body>
     84 </html>