Bug 1338862 - Update tests for WEBGL_debug_renderer_info. - r=daoshengmu
authorJeff Gilbert <jgilbert@mozilla.com>
Mon, 13 Feb 2017 15:22:04 -0800
changeset 372813 5387e70bd9c5c876d7d4ab1ba879977f134dda16
parent 372812 2fe83738221a0d438ccd33ffe8c9ee3c980c1ab3
child 372814 4f8aecb0f44f4801e6c277077e788516e6dd31de
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaoshengmu
bugs1338862
milestone54.0a1
Bug 1338862 - Update tests for WEBGL_debug_renderer_info. - r=daoshengmu MozReview-Commit-ID: HkFj3pc6EzE
dom/canvas/test/chrome/chrome.ini
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/ensure-exts/test_common.html
--- a/dom/canvas/test/chrome/chrome.ini
+++ b/dom/canvas/test/chrome/chrome.ini
@@ -1,8 +1,7 @@
 [DEFAULT]
-skip-if = os == 'android'
-support-files = nonchrome_webgl_debug_renderer_info.html
 
 [test_webgl_debug_renderer_info.html]
 subsuite = gpu
 [test_drawWindow_widget_layers.html]
+skip-if = os == 'android'
 support-files = ../file_drawWindow_source.html ../file_drawWindow_common.js
deleted file mode 100644
--- a/dom/canvas/test/chrome/nonchrome_webgl_debug_renderer_info.html
+++ /dev/null
@@ -1,83 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<script>
-
-
-// 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) {
-    var canBeUnprivileged = e.data.canBeUnprivileged;
-    run(canBeUnprivileged);
-  }
-}
-
-window.addEventListener("message", messageListener, true);
-
-function run(canBeUnprivileged) {
-  const UNMASKED_VENDOR_WEBGL = 0x9245;
-  const UNMASKED_RENDERER_WEBGL = 0x9246;
-
-  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 (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_OR_BETAs");
-
-    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_OR_BETAs");
-
-    ok(gl.getParameter(UNMASKED_VENDOR_WEBGL) && gl.getError() == gl.NO_ERROR,
-       "Should be able to query UNMASKED_VENDOR_WEBGL if enabling"
-       + " WEBGL_debug_renderer_info succeeded");
-    ok(gl.getParameter(UNMASKED_RENDERER_WEBGL) && gl.getError() == gl.NO_ERROR,
-       "Should be able to query UNMASKED_RENDERER_WEBGL if enabling"
-       + " WEBGL_debug_renderer_info succeeded");
-  } else {
-    ok(exts.indexOf("WEBGL_debug_renderer_info") == -1,
-       "WEBGL_debug_renderer_info should not be listed by getSupportedExtensions in"
-       + " non-chrome contexts");
-    var ext = gl.getExtension("WEBGL_debug_renderer_info");
-    ok(!ext,
-       "WEBGL_debug_renderer_info should not be available through getExtension in"
-       + " non-chrome contexts");
-
-    ok(!gl.getParameter(UNMASKED_VENDOR_WEBGL) && gl.getError() == gl.INVALID_ENUM,
-        "Should not be able to query UNMASKED_VENDOR_WEBGL if enabling"
-        + " WEBGL_debug_renderer_info failed");
-    ok(!gl.getParameter(UNMASKED_RENDERER_WEBGL) && gl.getError() == gl.INVALID_ENUM,
-        "Should not be able to query UNMASKED_RENDERER_WEBGL if enabling"
-        + " WEBGL_debug_renderer_info failed");
-
-  }
-  window.postMessage({allTestsFinished: true}, "*");
-}
-
-</script>
-</html>
--- a/dom/canvas/test/chrome/test_webgl_debug_renderer_info.html
+++ b/dom/canvas/test/chrome/test_webgl_debug_renderer_info.html
@@ -1,102 +1,51 @@
 <!DOCTYPE HTML>
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=666446
 -->
 <head>
-  <title>Test for WEBGL_debug_renderer_info chrome-only extension</title>
+  <title>Test that WEBGL_debug_renderer_info works in chrome code</title>
   <script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
 </head>
 <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 RELEASE_OR_BETA.
-// This should match AppConstants.RELEASE_OR_BETA.
-
-const canBeUnprivileged = !AppConstants.RELEASE_OR_BETA;
-
-
-function isNonEmptyString(s)
-{
+function isNonEmptyString(s) {
   return s && (typeof s) == "string";
 }
 
-function messageListener(e) {
-  if (e.data.allTestsFinished) {
-    SimpleTest.finish();
-  } else if (e.data.subTestFinished) {
-    ok(e.data.result, "content iframe: " + e.data.message);
-  }
-}
-
-function checkChromeCase(canvas) {
-
-  var gl = canvas.getContext("experimental-webgl");
-  ok(!gl.getError(), "getError on newly created WebGL context should return NO_ERROR");
+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();
-  ok(exts.indexOf("WEBGL_debug_renderer_info") != -1,
-     "WEBGL_debug_renderer_info should be listed by getSupportedExtensions in chrome contexts");
-  var ext = gl.getExtension("WEBGL_debug_renderer_info");
-  ok(ext,
-     "WEBGL_debug_renderer_info should be available through getExtension in chrome contexts");
-
-  ok(ext.UNMASKED_VENDOR_WEBGL == UNMASKED_VENDOR_WEBGL,
-     "UNMASKED_VENDOR_WEBGL has the correct value");
-  ok(ext.UNMASKED_RENDERER_WEBGL == UNMASKED_RENDERER_WEBGL,
-     "UNMASKED_RENDERER_WEBGL has the correct value");
+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");
 
-  ok(isNonEmptyString(gl.getParameter(UNMASKED_VENDOR_WEBGL)) && gl.getError() == gl.NO_ERROR,
-     "Should be able to query UNMASKED_VENDOR_WEBGL in chrome context with WEBGL_debug_renderer_info enabled");
-  ok(isNonEmptyString(gl.getParameter(UNMASKED_RENDERER_WEBGL)) && gl.getError() == gl.NO_ERROR,
-     "Should be able to query UNMASKED_RENDERER_WEBGL in chrome context with WEBGL_debug_renderer_info enabled");
-}
-
-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 = "http://mochi.test:8888/chrome/dom/canvas/test/chrome/nonchrome_webgl_debug_renderer_info.html";
+var exts = gl.getSupportedExtensions();
+ok(exts.indexOf("WEBGL_debug_renderer_info") != -1,
+   "WEBGL_debug_renderer_info should be listed by getSupportedExtensions in chrome contexts");
+var ext = gl.getExtension("WEBGL_debug_renderer_info");
+ok(ext,
+   "WEBGL_debug_renderer_info should be available through getExtension in chrome contexts");
 
-  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"));
+ok(ext.UNMASKED_VENDOR_WEBGL == UNMASKED_VENDOR_WEBGL,
+   "UNMASKED_VENDOR_WEBGL has the correct value");
+ok(ext.UNMASKED_RENDERER_WEBGL == UNMASKED_RENDERER_WEBGL,
+   "UNMASKED_RENDERER_WEBGL has the correct value");
 
-    iframe.contentWindow.addEventListener("message", messageListener);
-    iframe.contentWindow.postMessage({run: true,
-                                      canBeUnprivileged: canBeUnprivileged},
-                                     "*");
-  };
+ok(isNonEmptyString(gl.getParameter(UNMASKED_VENDOR_WEBGL)) && gl.getError() == gl.NO_ERROR,
+   "Should be able to query UNMASKED_VENDOR_WEBGL in chrome context with WEBGL_debug_renderer_info enabled");
+ok(isNonEmptyString(gl.getParameter(UNMASKED_RENDERER_WEBGL)) && gl.getError() == gl.NO_ERROR,
+   "Should be able to query UNMASKED_RENDERER_WEBGL in chrome context with WEBGL_debug_renderer_info enabled");
 
-  document.body.appendChild(iframe);
-}
-
-window.onload = main;
 </script>
-</pre>
 </body>
 </html>
--- a/dom/canvas/test/webgl-mochitest/ensure-exts/test_common.html
+++ b/dom/canvas/test/webgl-mochitest/ensure-exts/test_common.html
@@ -26,17 +26,17 @@ var defaultExts = [
     ['OES_element_index_uint'        , [ENSURE          , FORBID          ]],
     ['OES_standard_derivatives'      , [MACHINE_SPECIFIC, FORBID          ]],
     ['OES_texture_float'             , [ENSURE          , FORBID          ]],
     ['OES_texture_float_linear'      , [ENSURE          , ENSURE          ]],
     ['OES_texture_half_float'        , [ENSURE          , FORBID          ]],
     ['OES_texture_half_float_linear' , [ENSURE          , FORBID          ]],
     ['OES_vertex_array_object'       , [ENSURE          , FORBID          ]],
     ['WEBGL_compressed_texture_s3tc' , [MACHINE_SPECIFIC, MACHINE_SPECIFIC]],
-//  ['WEBGL_debug_renderer_info'     , [FORBID          , FORBID          ]], // Complicated!
+    ['WEBGL_debug_renderer_info'     , [ENSURE          , ENSURE          ]],
     ['WEBGL_debug_shaders'           , [FORBID          , FORBID          ]],
     ['WEBGL_depth_texture'           , [MACHINE_SPECIFIC, FORBID          ]],
     ['WEBGL_draw_buffers'            , [MACHINE_SPECIFIC, FORBID          ]],
     ['WEBGL_lose_context'            , [ENSURE          , ENSURE          ]],
 
     // Community Approved
     ['EXT_color_buffer_float'        , [FORBID          , ENSURE          ]],
     ['EXT_color_buffer_half_float'   , [MACHINE_SPECIFIC, FORBID          ]],