1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/chrome/test_webgl_debug_renderer_info.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=666446 1.8 +--> 1.9 +<head> 1.10 + <title>Test for WEBGL_debug_renderer_info chrome-only extension</title> 1.11 + <script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script> 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 1.14 +</head> 1.15 +<body> 1.16 + 1.17 +<pre id="test"> 1.18 +<script> 1.19 + 1.20 +const UNMASKED_VENDOR_WEBGL = 0x9245; 1.21 +const UNMASKED_RENDERER_WEBGL = 0x9246; 1.22 + 1.23 +function isNonEmptyString(s) 1.24 +{ 1.25 + return s && (typeof s) == "string"; 1.26 +} 1.27 + 1.28 +function messageListener(e) { 1.29 + if (e.data.allTestsFinished) { 1.30 + SimpleTest.finish(); 1.31 + } else if (e.data.subTestFinished) { 1.32 + ok(e.data.result, "content iframe: " + e.data.message); 1.33 + } 1.34 +} 1.35 + 1.36 +function checkChromeCase(canvas) { 1.37 + 1.38 + var gl = canvas.getContext("experimental-webgl"); 1.39 + ok(!gl.getError(), "getError on newly created WebGL context should return NO_ERROR"); 1.40 + 1.41 + ok(!gl.getParameter(UNMASKED_VENDOR_WEBGL) && gl.getError() == gl.INVALID_ENUM, 1.42 + "Should not be able to query UNMASKED_VENDOR_WEBGL without having enabled the WEBGL_debug_renderer_info extension"); 1.43 + ok(!gl.getParameter(UNMASKED_RENDERER_WEBGL) && gl.getError() == gl.INVALID_ENUM, 1.44 + "Should not be able to query UNMASKED_RENDERER_WEBGL without having enabled the WEBGL_debug_renderer_info extension"); 1.45 + 1.46 + var exts = gl.getSupportedExtensions(); 1.47 + ok(exts.indexOf("WEBGL_debug_renderer_info") != -1, 1.48 + "WEBGL_debug_renderer_info should be listed by getSupportedExtensions in chrome contexts"); 1.49 + var debugRendererInfoExtension = gl.getExtension("WEBGL_debug_renderer_info"); 1.50 + ok(debugRendererInfoExtension, 1.51 + "WEBGL_debug_renderer_info should be available through getExtension in chrome contexts"); 1.52 + 1.53 + ok(debugRendererInfoExtension.UNMASKED_VENDOR_WEBGL == UNMASKED_VENDOR_WEBGL, 1.54 + "UNMASKED_VENDOR_WEBGL has the correct value"); 1.55 + ok(debugRendererInfoExtension.UNMASKED_RENDERER_WEBGL == UNMASKED_RENDERER_WEBGL, 1.56 + "UNMASKED_RENDERER_WEBGL has the correct value"); 1.57 + 1.58 + ok(isNonEmptyString(gl.getParameter(UNMASKED_VENDOR_WEBGL)) && gl.getError() == gl.NO_ERROR, 1.59 + "Should be able to query UNMASKED_VENDOR_WEBGL in chrome context with WEBGL_debug_renderer_info enabled"); 1.60 + ok(isNonEmptyString(gl.getParameter(UNMASKED_RENDERER_WEBGL)) && gl.getError() == gl.NO_ERROR, 1.61 + "Should be able to query UNMASKED_RENDERER_WEBGL in chrome context with WEBGL_debug_renderer_info enabled"); 1.62 +} 1.63 + 1.64 +function main() 1.65 +{ 1.66 + SimpleTest.waitForExplicitFinish(); 1.67 + 1.68 + checkChromeCase(document.createElement("canvas")); 1.69 + 1.70 + // Now run the non-chrome code to verify the security of this WebGL chrome-only extension. 1.71 + 1.72 + var iframe = document.createElement("iframe"); 1.73 + iframe.src = "http://mochi.test:8888/chrome/content/canvas/test/chrome/nonchrome_webgl_debug_renderer_info.html"; 1.74 + 1.75 + iframe.onload = function () { 1.76 + 1.77 + // test that chrome can get WEBGL_debug_renderer_info on a canvas on the iframe... 1.78 + // this is useful to check in itself, and is also useful so the subsequent non-chrome test 1.79 + // will also test that doing so doesn't confuse our chrome-only check. 1.80 + checkChromeCase(iframe.contentDocument.createElement("canvas")); 1.81 + 1.82 + iframe.contentWindow.addEventListener("message", messageListener, false); 1.83 + iframe.contentWindow.postMessage("run", "*"); 1.84 + }; 1.85 + 1.86 + document.body.appendChild(iframe); 1.87 +} 1.88 + 1.89 +window.onload = main; 1.90 +</script> 1.91 +</pre> 1.92 +</body> 1.93 +</html>