Add shortcuts for common widget conditions. (Bug 570329) r=roc
authorL. David Baron <dbaron@dbaron.org>
Tue, 08 Jun 2010 18:44:32 -0700
changeset 43354 f9e8bdcb48cdce1d32e25b57b789da385d0b869a
parent 43353 f3d46038a7941479ed3161eb7338e9e33e5ecb54
child 43355 665863f2ac3180923cb58b91a92e0297a9edccdd
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs570329
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Add shortcuts for common widget conditions. (Bug 570329) r=roc
layout/tools/reftest/README.txt
layout/tools/reftest/reftest.js
--- a/layout/tools/reftest/README.txt
+++ b/layout/tools/reftest/README.txt
@@ -93,20 +93,24 @@ 2. A test item
           Loading the test and reference is known to assert between
           minCount and maxCount times, inclusive.
           NOTE: See above regarding canvas caching.
 
       asserts-if(condition,count)
       asserts-if(condition,minCount-maxCount)
           Same as above, but only if condition is true.
 
+      Conditions are JavaScript expressions *without spaces* in them.
+      They are evaluated in a sandbox in which a limited set of
+      variables are defined.  See the BuildConditionSandbox function in
+      layout/tools/reftest.js for details.
+
       Examples of using conditions:
-          fails-if(MOZ_WIDGET_TOOLKIT=="windows") ...
-          fails-if(MOZ_WIDGET_TOOLKIT=="cocoa") ...
-          fails-if(MOZ_WIDGET_TOOLKIT=="gtk2") ...
+          fails-if(winWidget) == test reference
+          asserts-if(2,cocoaWidget) load crashtest
 
    b. <http>, if present, is one of the strings (sans quotes) "HTTP" or
       "HTTP(..)" or "HTTP(../..)" or "HTTP(../../..)", etc. , indicating that
       the test should be run over an HTTP server because it requires certain
       HTTP headers or a particular HTTP status.  (Don't use this if your test
       doesn't require this functionality, because it unnecessarily slows down
       the test.)
 
--- a/layout/tools/reftest/reftest.js
+++ b/layout/tools/reftest/reftest.js
@@ -293,28 +293,36 @@ function getStreamContent(inputStream)
   
   return streamBuf;
 }
 
 // Build the sandbox for fails-if(), etc., condition evaluation.
 function BuildConditionSandbox(aURL) {
     var sandbox = new Components.utils.Sandbox(aURL.spec);
     var xr = CC[NS_XREAPPINFO_CONTRACTID].getService(CI.nsIXULRuntime);
-    sandbox.MOZ_WIDGET_TOOLKIT = xr.widgetToolkit;
     sandbox.isDebugBuild = gDebug.isDebugBuild;
     sandbox.xulRuntime = {widgetToolkit: xr.widgetToolkit, OS: xr.OS};
 
     // xr.XPCOMABI throws exception for configurations without full ABI
     // support (mobile builds on ARM)
     try {
       sandbox.xulRuntime.XPCOMABI = xr.XPCOMABI;
     } catch(e) {
       sandbox.xulRuntime.XPCOMABI = "";
     }
 
+    // Backwards compatibility from when we preprocessed autoconf.mk.
+    sandbox.MOZ_WIDGET_TOOLKIT = xr.widgetToolkit;
+
+    // Shortcuts for widget toolkits.
+    sandbox.cocoaWidget = xr.widgetToolkit == "cocoa";
+    sandbox.gtk2Widget = xr.widgetToolkit == "gtk2";
+    sandbox.qtWidget = xr.widgetToolkit == "qt";
+    sandbox.winWidget = xr.widgetToolkit == "windows";
+
     var hh = CC[NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX + "http"].
                  getService(CI.nsIHttpProtocolHandler);
     sandbox.http = {};
     for each (var prop in [ "userAgent", "appName", "appVersion",
                             "vendor", "vendorSub", "vendorComment",
                             "product", "productSub", "productComment",
                             "platform", "oscpu", "language", "misc" ])
         sandbox.http[prop] = hh[prop];