content/canvas/test/chrome/test_webgl_debug_renderer_info.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=666446
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for WEBGL_debug_renderer_info chrome-only extension</title>
michael@0 8 <script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
michael@0 9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
michael@0 11 </head>
michael@0 12 <body>
michael@0 13
michael@0 14 <pre id="test">
michael@0 15 <script>
michael@0 16
michael@0 17 const UNMASKED_VENDOR_WEBGL = 0x9245;
michael@0 18 const UNMASKED_RENDERER_WEBGL = 0x9246;
michael@0 19
michael@0 20 function isNonEmptyString(s)
michael@0 21 {
michael@0 22 return s && (typeof s) == "string";
michael@0 23 }
michael@0 24
michael@0 25 function messageListener(e) {
michael@0 26 if (e.data.allTestsFinished) {
michael@0 27 SimpleTest.finish();
michael@0 28 } else if (e.data.subTestFinished) {
michael@0 29 ok(e.data.result, "content iframe: " + e.data.message);
michael@0 30 }
michael@0 31 }
michael@0 32
michael@0 33 function checkChromeCase(canvas) {
michael@0 34
michael@0 35 var gl = canvas.getContext("experimental-webgl");
michael@0 36 ok(!gl.getError(), "getError on newly created WebGL context should return NO_ERROR");
michael@0 37
michael@0 38 ok(!gl.getParameter(UNMASKED_VENDOR_WEBGL) && gl.getError() == gl.INVALID_ENUM,
michael@0 39 "Should not be able to query UNMASKED_VENDOR_WEBGL without having enabled the WEBGL_debug_renderer_info extension");
michael@0 40 ok(!gl.getParameter(UNMASKED_RENDERER_WEBGL) && gl.getError() == gl.INVALID_ENUM,
michael@0 41 "Should not be able to query UNMASKED_RENDERER_WEBGL without having enabled the WEBGL_debug_renderer_info extension");
michael@0 42
michael@0 43 var exts = gl.getSupportedExtensions();
michael@0 44 ok(exts.indexOf("WEBGL_debug_renderer_info") != -1,
michael@0 45 "WEBGL_debug_renderer_info should be listed by getSupportedExtensions in chrome contexts");
michael@0 46 var debugRendererInfoExtension = gl.getExtension("WEBGL_debug_renderer_info");
michael@0 47 ok(debugRendererInfoExtension,
michael@0 48 "WEBGL_debug_renderer_info should be available through getExtension in chrome contexts");
michael@0 49
michael@0 50 ok(debugRendererInfoExtension.UNMASKED_VENDOR_WEBGL == UNMASKED_VENDOR_WEBGL,
michael@0 51 "UNMASKED_VENDOR_WEBGL has the correct value");
michael@0 52 ok(debugRendererInfoExtension.UNMASKED_RENDERER_WEBGL == UNMASKED_RENDERER_WEBGL,
michael@0 53 "UNMASKED_RENDERER_WEBGL has the correct value");
michael@0 54
michael@0 55 ok(isNonEmptyString(gl.getParameter(UNMASKED_VENDOR_WEBGL)) && gl.getError() == gl.NO_ERROR,
michael@0 56 "Should be able to query UNMASKED_VENDOR_WEBGL in chrome context with WEBGL_debug_renderer_info enabled");
michael@0 57 ok(isNonEmptyString(gl.getParameter(UNMASKED_RENDERER_WEBGL)) && gl.getError() == gl.NO_ERROR,
michael@0 58 "Should be able to query UNMASKED_RENDERER_WEBGL in chrome context with WEBGL_debug_renderer_info enabled");
michael@0 59 }
michael@0 60
michael@0 61 function main()
michael@0 62 {
michael@0 63 SimpleTest.waitForExplicitFinish();
michael@0 64
michael@0 65 checkChromeCase(document.createElement("canvas"));
michael@0 66
michael@0 67 // Now run the non-chrome code to verify the security of this WebGL chrome-only extension.
michael@0 68
michael@0 69 var iframe = document.createElement("iframe");
michael@0 70 iframe.src = "http://mochi.test:8888/chrome/content/canvas/test/chrome/nonchrome_webgl_debug_renderer_info.html";
michael@0 71
michael@0 72 iframe.onload = function () {
michael@0 73
michael@0 74 // test that chrome can get WEBGL_debug_renderer_info on a canvas on the iframe...
michael@0 75 // this is useful to check in itself, and is also useful so the subsequent non-chrome test
michael@0 76 // will also test that doing so doesn't confuse our chrome-only check.
michael@0 77 checkChromeCase(iframe.contentDocument.createElement("canvas"));
michael@0 78
michael@0 79 iframe.contentWindow.addEventListener("message", messageListener, false);
michael@0 80 iframe.contentWindow.postMessage("run", "*");
michael@0 81 };
michael@0 82
michael@0 83 document.body.appendChild(iframe);
michael@0 84 }
michael@0 85
michael@0 86 window.onload = main;
michael@0 87 </script>
michael@0 88 </pre>
michael@0 89 </body>
michael@0 90 </html>

mercurial