Bug 1192989 - Simplify handling by ifdefing in all.js. r=kamidphish, a=sylvestre
authorJeff Gilbert <jgilbert@mozilla.com>
Mon, 10 Aug 2015 14:57:15 -0700
changeset 297829 22bb71109bd6ff13422c26ecee1cb4dd018ee5da
parent 297828 75399486db0a1388629059cf910f10776ba283c3
child 297830 4353ea1e784e6bc70e43df36eaba4eac497e7cc0
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskamidphish, sylvestre
bugs1192989
milestone43.0a2
Bug 1192989 - Simplify handling by ifdefing in all.js. r=kamidphish, a=sylvestre
dom/canvas/WebGLContextExtensions.cpp
dom/canvas/test/chrome/nonchrome_webgl_debug_renderer_info.html
dom/canvas/test/chrome/test_webgl_debug_renderer_info.html
dom/canvas/test/webgl-mochitest/test_renderer_strings.html
modules/libpref/init/all.js
--- a/dom/canvas/WebGLContextExtensions.cpp
+++ b/dom/canvas/WebGLContextExtensions.cpp
@@ -156,28 +156,18 @@ WebGLContext::IsExtensionSupported(WebGL
         if (gl->IsExtensionSupported(gl::GLContext::EXT_texture_compression_s3tc))
             return true;
 
         return gl->IsExtensionSupported(gl::GLContext::EXT_texture_compression_dxt1) &&
                gl->IsExtensionSupported(gl::GLContext::ANGLE_texture_compression_dxt3) &&
                gl->IsExtensionSupported(gl::GLContext::ANGLE_texture_compression_dxt5);
 
     case WebGLExtensionID::WEBGL_debug_renderer_info:
-        {
-            bool isEnabled = true;
+        return Preferences::GetBool("webgl.enable-debug-renderer-info", false);
 
-#ifdef RELEASE_BUILD
-            // Keep this disabled on Release and Beta for now. (see bug 1171228)
-            isEnabled = false;
-#endif
-            if (Preferences::GetBool("webgl.disable-debug-renderer-info", false))
-                isEnabled = false;
-
-            return isEnabled;
-        }
     case WebGLExtensionID::WEBGL_depth_texture:
         // WEBGL_depth_texture supports DEPTH_STENCIL textures
         if (!gl->IsSupported(gl::GLFeature::packed_depth_stencil))
             return false;
 
         return gl->IsSupported(gl::GLFeature::depth_texture) ||
                gl->IsExtensionSupported(gl::GLContext::ANGLE_depth_texture);
     case WebGLExtensionID::WEBGL_draw_buffers:
--- a/dom/canvas/test/chrome/nonchrome_webgl_debug_renderer_info.html
+++ b/dom/canvas/test/chrome/nonchrome_webgl_debug_renderer_info.html
@@ -1,62 +1,54 @@
 <!DOCTYPE HTML>
 <html>
 <script>
 
-var Cu = parent.Components.utils;
-Cu.import("resource://gre/modules/AppConstants.jsm");
-// This gives us `AppConstants` in the global scope.
-// We need this because we only expose debug_renderer_info #ifndef MOZ_RELEASE_BUILD.
-// This should match AppConstants.RELEASE_BUILD.
 
 // This file has the portion of the test_webgl_renderer_info chrome mochitest
 // that has to run as non-chrome to check that this WebGL extension is not exposed to content
 
 // we can't call the chrome Mochitest ok() function ourselves from non-chrome code.
 // So we remote it to the chrome test.
 
 function ok(res, msg) {
   // Note we post to ourselves as posting to the chrome code doesn't seem to work here.
   // This works by having the chrome code put an event handler on our own window.
   window.postMessage({ subTestFinished: true, result: res, message: msg }, "*");
 }
 
 function messageListener(e) {
   // This is how the chrome test tells us to start running -- we have to wait for this
   // message to avoid running before it's set up its event handler.
-  if (e.data == "run") {
-    run();
+  if (e.data.run) {
+    var canBeUnprivileged = e.data.canBeUnprivileged;
+    run(canBeUnprivileged);
   }
 }
 
 window.addEventListener("message", messageListener, true);
 
-function run() {
+function run(canBeUnprivileged) {
   const UNMASKED_VENDOR_WEBGL = 0x9245;
   const UNMASKED_RENDERER_WEBGL = 0x9246;
 
-  var shouldHaveRendererInfo = false;
-  if (!AppConstants.RELEASE_BUILD)
-    shouldHaveRendererInfo = true;
-
   var canvas = document.createElement("canvas");
   var gl = canvas.getContext("experimental-webgl");
 
   ok(!gl.getError(), "getError on newly created WebGL context should return NO_ERROR");
 
   ok(!gl.getParameter(UNMASKED_VENDOR_WEBGL) && gl.getError() == gl.INVALID_ENUM,
       "Should not be able to query UNMASKED_VENDOR_WEBGL without having enabled the"
       + " WEBGL_debug_renderer_info extension");
   ok(!gl.getParameter(UNMASKED_RENDERER_WEBGL) && gl.getError() == gl.INVALID_ENUM,
       "Should not be able to query UNMASKED_RENDERER_WEBGL without having enabled the"
       + " WEBGL_debug_renderer_info extension");
 
   var exts = gl.getSupportedExtensions();
-  if (shouldHaveRendererInfo) {
+  if (canBeUnprivileged) {
     ok(exts.indexOf("WEBGL_debug_renderer_info") != -1,
        "WEBGL_debug_renderer_info should be listed by getSupportedExtensions in"
        + " non-chrome contexts on non-RELEASE_BUILDs");
 
     var ext = gl.getExtension("WEBGL_debug_renderer_info");
     ok(!!ext,
        "WEBGL_debug_renderer_info should be available through getExtension in non-chrome"
        + " contexts on non-RELEASE_BUILDs");
--- a/dom/canvas/test/chrome/test_webgl_debug_renderer_info.html
+++ b/dom/canvas/test/chrome/test_webgl_debug_renderer_info.html
@@ -12,16 +12,26 @@ https://bugzilla.mozilla.org/show_bug.cg
 <body>
 
 <pre id="test">
 <script>
 
 const UNMASKED_VENDOR_WEBGL = 0x9245;
 const UNMASKED_RENDERER_WEBGL = 0x9246;
 
+
+var Cu = parent.Components.utils;
+Cu.import("resource://gre/modules/AppConstants.jsm");
+// This gives us `AppConstants` in the global scope.
+// We need this because we only expose debug_renderer_info #ifndef MOZ_RELEASE_BUILD.
+// This should match AppConstants.RELEASE_BUILD.
+
+const canBeUnprivileged = !AppConstants.RELEASE_BUILD;
+
+
 function isNonEmptyString(s)
 {
   return s && (typeof s) == "string";
 }
 
 function messageListener(e) {
   if (e.data.allTestsFinished) {
     SimpleTest.finish();
@@ -62,27 +72,29 @@ function main()
 {
   SimpleTest.waitForExplicitFinish();
 
   checkChromeCase(document.createElement("canvas"));
 
   // Now run the non-chrome code to verify the security of this WebGL chrome-only extension.
 
   var iframe = document.createElement("iframe");
-  iframe.src = "chrome://mochitests/content/chrome/dom/canvas/test/chrome/nonchrome_webgl_debug_renderer_info.html";
+  iframe.src = "http://mochi.test:8888/chrome/dom/canvas/test/chrome/nonchrome_webgl_debug_renderer_info.html";
 
   iframe.onload = function () {
 
     // test that chrome can get WEBGL_debug_renderer_info on a canvas on the iframe...
     // this is useful to check in itself, and is also useful so the subsequent non-chrome test
     // will also test that doing so doesn't confuse our chrome-only check.
     checkChromeCase(iframe.contentDocument.createElement("canvas"));
 
     iframe.contentWindow.addEventListener("message", messageListener, false);
-    iframe.contentWindow.postMessage("run", "*");
+    iframe.contentWindow.postMessage({run: true,
+                                      canBeUnprivileged: canBeUnprivileged},
+                                     "*");
   };
 
   document.body.appendChild(iframe);
 }
 
 window.onload = main;
 </script>
 </pre>
--- a/dom/canvas/test/webgl-mochitest/test_renderer_strings.html
+++ b/dom/canvas/test/webgl-mochitest/test_renderer_strings.html
@@ -7,74 +7,78 @@
 <body>
 <script>
 
 function AssertError(gl, expected, info) {
   var actual = gl.getError();
   while (gl.getError()) {}
 
   ok(actual == expected,
-     'For ' + info + ', expected 0x' + expected.toString(16) + ', got 0x'
+     'For ' + info + ', expected GL error 0x' + expected.toString(16) + ', got 0x'
       + actual.toString(16));
 }
 
 var gl;
 
 var RENDERER_OVERRIDE = 'overridden renderer';
 var VENDOR_OVERRIDE = 'overridden vendor';
 
 function TestExt() {
   var ext = gl.getExtension('WEBGL_debug_renderer_info');
-  ok(ext, 'Should have access to \'WEBGL_debug_renderer_info\'.');
+  ok(ext, 'When pref enabled: Should have access to \'WEBGL_debug_renderer_info\'.');
   AssertError(gl, 0, 'start of test');
 
   var renderer = gl.getParameter(ext.UNMASKED_RENDERER_WEBGL);
   AssertError(gl, 0, 'UNMASKED_RENDERER_WEBGL');
   ok(renderer,
-     'UNMASKED_RENDERER_WEBGL value should not be empty, was \'' + renderer + '\'');
+     'When pref enabled: UNMASKED_RENDERER_WEBGL value should not be empty, was \''
+     + renderer + '\'');
 
   var vendor = gl.getParameter(ext.UNMASKED_VENDOR_WEBGL);
   AssertError(gl, 0, 'UNMASKED_VENDOR_WEBGL');
-  ok(vendor, 'UNMASKED_VENDOR_WEBGL value should not be empty, was \'' + vendor + '\'');
+  ok(vendor,
+     'When pref enabled: UNMASKED_VENDOR_WEBGL value should not be empty, was \''
+     + vendor + '\'');
 
   var prefArrArr = [
     ['webgl.renderer-string-override', RENDERER_OVERRIDE],
     ['webgl.vendor-string-override', VENDOR_OVERRIDE],
   ];
   var prefEnv = {'set': prefArrArr};
   SpecialPowers.pushPrefEnv(prefEnv, TestOverrides);
 }
 
 function TestOverrides() {
   var ext = gl.getExtension('WEBGL_debug_renderer_info');
-  ok(ext, 'Should have access to \'WEBGL_debug_renderer_info\'.');
+  ok(ext, 'When overrides set: Should have access to \'WEBGL_debug_renderer_info\'.');
   AssertError(gl, 0, 'start of test');
 
   var renderer = gl.getParameter(ext.UNMASKED_RENDERER_WEBGL);
   AssertError(gl, 0, 'UNMASKED_RENDERER_WEBGL');
   ok(renderer == RENDERER_OVERRIDE,
-     'UNMASKED_RENDERER_WEBGL value should be \'' + RENDERER_OVERRIDE + '\', was \''
-     + renderer + '\'');
+     'When overrides set: UNMASKED_RENDERER_WEBGL value should be \'' + RENDERER_OVERRIDE
+     + '\', was \'' + renderer + '\'');
 
   var vendor = gl.getParameter(ext.UNMASKED_VENDOR_WEBGL);
   AssertError(gl, 0, 'UNMASKED_VENDOR_WEBGL');
   ok(vendor == VENDOR_OVERRIDE,
-     'UNMASKED_VENDOR_WEBGL value should be \'' + VENDOR_OVERRIDE + '\', was \'' + vendor
-     + '\'');
+     'When overrides set: UNMASKED_VENDOR_WEBGL value should be \'' + VENDOR_OVERRIDE
+     + '\', was \'' + vendor + '\'');
 
   var prefArrArr = [
-    ['webgl.disable-debug-renderer-info', true],
+    ['webgl.enable-debug-renderer-info', false],
   ];
   var prefEnv = {'set': prefArrArr};
   SpecialPowers.pushPrefEnv(prefEnv, TestDisable);
 }
 
 function TestDisable() {
   var ext = gl.getExtension('WEBGL_debug_renderer_info');
-  ok(!ext, 'Should not have access to \'WEBGL_debug_renderer_info\'.');
+  ok(!ext,
+     'When pref disabled: Should not have access to \'WEBGL_debug_renderer_info\'.');
 
   ok(true, 'Test complete.');
   SimpleTest.finish();
 }
 
 (function() {
   var canvas = document.createElement('canvas');
   gl = canvas.getContext('experimental-webgl');
@@ -82,17 +86,17 @@ function TestDisable() {
     todo(gl, 'Get WebGL working here first.');
     ok(true, 'Test complete.');
     return;
   }
 
   SimpleTest.waitForExplicitFinish();
 
   var prefArrArr = [
-    ['webgl.disable-debug-renderer-info', false],
+    ['webgl.enable-debug-renderer-info', true],
   ];
   var prefEnv = {'set': prefArrArr};
   SpecialPowers.pushPrefEnv(prefEnv, TestExt);
 })();
 
 </script>
 </body>
 </html>
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -4157,17 +4157,24 @@ pref("webgl.lose-context-on-memory-press
 pref("webgl.can-lose-context-in-foreground", true);
 pref("webgl.restore-context-when-visible", true);
 pref("webgl.max-warnings-per-context", 32);
 pref("webgl.enable-draft-extensions", false);
 pref("webgl.enable-privileged-extensions", false);
 pref("webgl.bypass-shader-validation", false);
 pref("webgl.enable-prototype-webgl2", false);
 pref("webgl.disable-fail-if-major-performance-caveat", false);
-pref("webgl.disable-debug-renderer-info", false);
+
+#ifdef RELEASE_BUILD
+// Keep this disabled on Release and Beta for now. (see bug 1171228)
+pref("webgl.enable-debug-renderer-info", false);
+#else
+pref("webgl.enable-debug-renderer-info", true);
+#endif
+
 pref("webgl.renderer-string-override", "");
 pref("webgl.vendor-string-override", "");
 
 #ifdef XP_WIN
 pref("webgl.angle.try-d3d11", true);
 pref("webgl.angle.force-d3d11", false);
 pref("webgl.angle.force-warp", false);
 #endif