context-lost.html (2134B)
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 function init() 16 { 17 description("Tests behavior under a lost context for OffscreenCanvas"); 18 19 if (!window.OffscreenCanvas) { 20 testPassed("No OffscreenCanvas support"); 21 finishTest(); 22 return; 23 } 24 25 canvas = new OffscreenCanvas(10, 10); 26 gl = canvas.getContext('webgl'); 27 28 // call testValidContext() before checking for the extension, because this is where we check 29 // for the isContextLost() method, which we want to do regardless of the extension's presence. 30 if (!testValidContext()) { 31 testFailed("Some tests failed"); 32 finishTest(); 33 return; 34 } 35 36 WEBGL_lose_context = gl.getExtension("WEBGL_lose_context"); 37 // need an extension that exposes new API methods. 38 OES_vertex_array_object = gl.getExtension("OES_vertex_array_object"); 39 if (WEBGL_lose_context == null || OES_vertex_array_object == null) { 40 testFailed("extension && OES_vertex_array_object failed"); 41 finishTest(); 42 return; 43 } 44 45 // We need to initialize |uniformLocation| before losing context. 46 // Otherwise gl.getUniform() when context is lost will throw. 47 uniformLocation = gl.getUniformLocation(program, "tex"); 48 WEBGL_lose_context.loseContext(); 49 50 canvas.addEventListener("webglcontextlost", function() { 51 if (testLostContextWithoutRestore()) { 52 testPassed("All tests passed"); 53 finishTest(); 54 return; 55 } else { 56 testFailed("testLostContextWithoutRestore failed"); 57 finishTest(); 58 return; 59 } 60 }, false); 61 } 62 63 </script> 64 </head> 65 <body onload="init()"> 66 <div id="description"></div> 67 <div id="console"></div> 68 </body> 69 </html>