1<!DOCTYPE html> 2<title>Testing GMs on WebGL 2 compiled with Bazel</title> 3<meta charset="utf-8" /> 4<meta http-equiv="X-UA-Compatible" content="IE=edge"> 5<meta name="viewport" content="width=device-width, initial-scale=1.0"> 6 7<script type="text/javascript" src="/build/wasm_gm_tests.js"></script> 8 9<p id="log"></p> 10<!-- Makes png visible to user --> 11<canvas id=png_canvas height=1000 width=1000></canvas> 12<!-- Used for drawing/testing, but nothing is visible --> 13<canvas id=gm_canvas></canvas> 14 15 16<script type="text/javascript" charset="utf-8"> 17 function log(line) { 18 console.log(line); 19 line += '\n'; 20 document.getElementById("log").innerText += line; 21 } 22 Run(); 23 async function Run() { 24 const TestRunner = await InitWasmGMTests({locateFile: (file) => '/build/'+file}); 25 TestRunner.Init(); 26 const gmNames = TestRunner.ListGMs(); 27 const testNames = TestRunner.ListTests(); 28 29 if (gmNames.length) { 30 await RunGM(TestRunner, gmNames[0]); 31 } 32 if (testNames.length) { 33 RunTest(TestRunner, testNames[0]); 34 } 35 } 36 37 async function RunGM(TestRunner, name) { 38 const canvas = document.getElementById('gm_canvas'); 39 const ctx = TestRunner.GetWebGLContext(canvas, 2); 40 const grcontext = TestRunner.MakeGrContext(ctx); 41 42 log("Running gm " + name); 43 const pngAndMetadata = TestRunner.RunGM(grcontext, name); 44 45 const b = new Blob([pngAndMetadata.png.buffer], {type: "image/png"}); 46 const bmp = await createImageBitmap(b); 47 const canvasCtx = document.getElementById("png_canvas").getContext("2d"); 48 canvasCtx.drawImage(bmp, 0, 0); 49 } 50 51 function RunTest(TestRunner, name) { 52 const canvas = document.getElementById('gm_canvas'); 53 const ctx = TestRunner.GetWebGLContext(canvas, 2); 54 // This sets up the GL context for all tests. We do not need to pass the grcontext in to the 55 // tests. The unit tests have a GrContextFactory which will do so as necessary. 56 // It *is* important to make sure we have at least initialized the WebGL context for this 57 // so the factory can work. 58 const grcontext = TestRunner.MakeGrContext(ctx); 59 if (!grcontext) { 60 window._error = 'Could not make GrContext for tests'; 61 return; 62 } 63 log("Running test " + name); 64 const result = TestRunner.RunTest(name); 65 log(' ' + result.result, result.msg || ''); 66 } 67</script>