tor-browser

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

context-lost-restored.html (2647B)


      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 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
     11 <script src="../../js/js-test-pre.js"></script>
     12 <script src="../../js/webgl-test-utils.js"></script>
     13 <script src="../../js/tests/canvas-tests-utils.js"></script>
     14 <script>
     15 
     16 function init()
     17 {
     18    description("Tests behavior under a restored context for OffscreenCanvas.");
     19 
     20    if (!window.OffscreenCanvas) {
     21      testPassed("No OffscreenCanvas support");
     22      finishTest();
     23      return;
     24    }
     25 
     26    if (!setupTest()) {
     27        testFailed("Cannot initialize test");
     28        finishTest();
     29        return;
     30    }
     31 
     32    canvas.addEventListener("webglcontextlost", function(e) {
     33        if (!testLostContext(e)) {
     34            testFailed("Some test failed");
     35            finishTest();
     36            return;
     37        }
     38        // restore the context after this event has exited.
     39        setTimeout(function() {
     40            // we didn't call prevent default so we should not be able to restore the context
     41            if (!compareGLError(gl.INVALID_OPERATION, "WEBGL_lose_context.restoreContext()")) {
     42                testFailed("Some test failed");
     43                finishTest();
     44                return;
     45            }
     46            testLosingAndRestoringContext().then(function(s) {
     47                testPassed("Test passed");
     48                finishTest();
     49                return;
     50            }, function(s) {
     51                testFailed("Test failed: " + s);
     52                finishTest();
     53                return;
     54            });
     55       }, 0);
     56    });
     57    canvas.addEventListener("webglcontextrestored", function() {
     58        testFailed("Some test failed");
     59        finishTest();
     60        return;
     61    });
     62    allowRestore = false;
     63    contextLostEventFired = false;
     64    contextRestoredEventFired = false;
     65 
     66    if (!testOriginalContext()) {
     67        testFailed("Some test failed");
     68        finishTest();
     69        return;
     70    }
     71    WEBGL_lose_context.loseContext();
     72    // The context should be lost immediately.
     73    shouldBeTrue("gl.isContextLost()");
     74    shouldBe("gl.getError()", "gl.CONTEXT_LOST_WEBGL");
     75    shouldBe("gl.getError()", "gl.NO_ERROR");
     76    // gl methods should be no-ops
     77    shouldBeTrue(compareGLError(gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP)"));
     78    // but the event should not have been fired.
     79    shouldBeFalse("contextLostEventFired");
     80 }
     81 
     82 </script>
     83 </head>
     84 <body onload="init()">
     85 <div id="description"></div>
     86 <div id="console"></div>
     87 </body>
     88 </html>