ensure-ext.js (1081B)
1 "use strict"; 2 3 function EnsureExt(extName, shouldHave = true) { 4 EnsureExtFor("webgl", extName, shouldHave); 5 EnsureExtFor("webgl2", extName, shouldHave); 6 } 7 8 function EnsureExtFor(contextType, extName, shouldHave = true) { 9 var c = document.createElement("canvas"); 10 var gl = c.getContext(contextType); 11 12 if (!gl) { 13 todo(false, "Failed to create context: " + contextType); 14 return; 15 } 16 17 var ext = gl.getExtension(extName); 18 var haveText = " have " + contextType + " extension " + extName + "."; 19 if (shouldHave) { 20 ok(ext, "Should" + haveText); 21 } else { 22 ok(!ext, "Should not" + haveText); 23 } 24 } 25 26 function Lastly_WithDraftExtsEnabled(func) { 27 SimpleTest.waitForExplicitFinish(); 28 29 var fnEnsure = function () { 30 func(); 31 SimpleTest.finish(); 32 }; 33 34 if ("SpecialPowers" in window) { 35 var prefStateList = [["webgl.enable-draft-extensions", true]]; 36 var prefEnv = { set: prefStateList }; 37 SpecialPowers.pushPrefEnv(prefEnv, fnEnsure); 38 } else { 39 console.log("Couldn't use SpecialPowers to enable draft extensions."); 40 fnEnsure(); 41 } 42 }