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