Allow mochitests that don't require chrome privileges to run in a normal profile. (Bug 570328) r=jwalden
authorL. David Baron <dbaron@dbaron.org>
Tue, 08 Jun 2010 18:44:31 -0700
changeset 43352 e89ae2aa45eb866a8bb7bee0a403d6ce9b52932e
parent 43351 396aec61ada24c2de120588911ea61fc0d393cc7
child 43353 f3d46038a7941479ed3161eb7338e9e33e5ecb54
push id13666
push userdbaron@mozilla.com
push dateWed, 09 Jun 2010 01:45:53 +0000
treeherdermozilla-central@979aceadf808 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs570328
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
Allow mochitests that don't require chrome privileges to run in a normal profile. (Bug 570328) r=jwalden
testing/mochitest/tests/SimpleTest/SimpleTest.js
--- a/testing/mochitest/tests/SimpleTest/SimpleTest.js
+++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js
@@ -429,28 +429,34 @@ SimpleTest.waitForClipboard = function(a
 }
 
 /**
  * Executes a function shortly after the call, but lets the caller continue
  * working (or finish).
  */
 SimpleTest.executeSoon = function(aFunc) {
     if ("Components" in window && "classes" in window.Components) {
-        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-        var tm = Components.classes["@mozilla.org/thread-manager;1"]
-                   .getService(Components.interfaces.nsIThreadManager);
+        try {
+            netscape.security.PrivilegeManager
+              .enablePrivilege("UniversalXPConnect");
+            var tm = Components.classes["@mozilla.org/thread-manager;1"]
+                       .getService(Components.interfaces.nsIThreadManager);
 
-        tm.mainThread.dispatch({
-            run: function() {
-                aFunc();
-            }
-        }, Components.interfaces.nsIThread.DISPATCH_NORMAL);
-    } else {
-        setTimeout(aFunc, 0);
+            tm.mainThread.dispatch({
+                run: function() {
+                    aFunc();
+                }
+            }, Components.interfaces.nsIThread.DISPATCH_NORMAL);
+            return;
+        } catch (ex) {
+            // If the above fails (most likely because of enablePrivilege
+            // failing, fall through to the setTimeout path.
+        }
     }
+    setTimeout(aFunc, 0);
 }
 
 /**
  * Finishes the tests. This is automatically called, except when
  * SimpleTest.waitForExplicitFinish() has been invoked.
 **/
 SimpleTest.finish = function () {
     if (parentRunner) {