Bug 504060: Add executeSoon equivalent to xpcshell tests. r=ted
authorDave Townsend <dtownsend@oxymoronical.com>
Thu, 06 Aug 2009 15:25:16 +0100
changeset 31173 5b5a412e9cd3dc5cf6f59a3d5f6390fe2ebd1029
parent 31172 5c913c4662d81b4767c33420ac589ee4aa2c5ad7
child 31174 91db32e73fc0091998efc1852d60a94d1450fd43
push id8407
push userdtownsend@mozilla.com
push dateThu, 06 Aug 2009 14:25:54 +0000
treeherdermozilla-central@91db32e73fc0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs504060
milestone1.9.2a1pre
Bug 504060: Add executeSoon equivalent to xpcshell tests. r=ted
testing/xpcshell/head.js
--- a/testing/xpcshell/head.js
+++ b/testing/xpcshell/head.js
@@ -172,16 +172,27 @@ function _load_files(aFiles) {
 
 
 function do_timeout(delay, expr) {
   var timer = Components.classes["@mozilla.org/timer;1"]
                         .createInstance(Components.interfaces.nsITimer);
   timer.initWithCallback(new _TimerCallback(expr), delay, timer.TYPE_ONE_SHOT);
 }
 
+function do_execute_soon(callback) {
+  var tm = Components.classes["@mozilla.org/thread-manager;1"]
+                     .getService(Components.interfaces.nsIThreadManager);
+
+  tm.mainThread.dispatch({
+    run: function() {
+      callback();
+    }
+  }, Components.interfaces.nsIThread.DISPATCH_NORMAL);
+}
+
 function do_throw(text, stack) {
   if (!stack)
     stack = Components.stack.caller;
 
   _passed = false;
   dump("TEST-UNEXPECTED-FAIL | " + stack.filename + " | " + text +
          " - See following stack:\n");
   var frame = Components.stack;