Bug 462338: Make executeSoon widely available. r=robcee, r=gavin
authorDave Townsend <dtownsend@oxymoronical.com>
Thu, 30 Oct 2008 17:22:17 +0000
changeset 21107 46a0fed0b3df6d782e09a3eba6102fe6f6d91e80
parent 21106 6fd85628b1dc1f1c4a7c95fc522d21f90861a426
child 21108 9b4084a61cd9d67d11d1ddbbeac442800ad4a2a1
push id3319
push userdtownsend@mozilla.com
push dateThu, 30 Oct 2008 17:23:40 +0000
treeherdermozilla-central@46a0fed0b3df [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobcee, gavin
bugs462338
milestone1.9.1b2pre
Bug 462338: Make executeSoon widely available. r=robcee, r=gavin
testing/mochitest/browser-test.js
testing/mochitest/tests/SimpleTest/SimpleTest.js
toolkit/mozapps/downloads/tests/chrome/test_retention_is_0_closes.xul
toolkit/mozapps/downloads/tests/chrome/test_unkownContentType_dialog_layout.xul
toolkit/mozapps/downloads/tests/chrome/utils.js
--- a/testing/mochitest/browser-test.js
+++ b/testing/mochitest/browser-test.js
@@ -131,16 +131,26 @@ function testScope(aTests) {
   };
   this.todo_is = function test_todo_is(a, b, name) {
     self.todo(a == b, name, "Got " + a + ", expected " + b);
   };
   this.todo_isnot = function test_todo_isnot(a, b, name) {
     self.todo(a != b, name, "Didn't expect " + a + ", but got it");
   };
 
+  this.executeSoon = function test_executeSoon(func) {
+    let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
+
+    tm.mainThread.dispatch({
+      run: function() {
+        func();
+      }
+    }, Ci.nsIThread.DISPATCH_NORMAL);
+  };
+
   this.waitForExplicitFinish = function test_WFEF() {
     self.done = false;
   };
   this.finish = function test_finish() {
     self.done = true;
   };
 }
 testScope.prototype = {
--- a/testing/mochitest/tests/SimpleTest/SimpleTest.js
+++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js
@@ -197,16 +197,31 @@ SimpleTest.showReport = function() {
  * When SimpleTest.waitForExplicitFinish is called,
  * explicit SimpleTest.finish() is required.
 **/
 SimpleTest.waitForExplicitFinish = function () {
     SimpleTest._stopOnLoad = false;
 };
 
 /**
+ * Executes a function shortly after the call, but lets the caller continue
+ * working (or finish).
+ */
+SimpleTest.executeSoon = function(aFunc) {
+    var tm = Components.classes["@mozilla.org/thread-manager;1"]
+                       .getService(Components.interfaces.nsIThreadManager);
+
+    tm.mainThread.dispatch({
+        run: function() {
+            aFunc();
+        }
+    }, Components.interfaces.nsIThread.DISPATCH_NORMAL);
+}
+
+/**
  * Talks to the TestRunner if being ran on a iframe and the parent has a
  * TestRunner object.
 **/
 SimpleTest.talkToRunner = function () {
     if (parentRunner) {
         parentRunner.testFinished(document);
     }
 };
--- a/toolkit/mozapps/downloads/tests/chrome/test_retention_is_0_closes.xul
+++ b/toolkit/mozapps/downloads/tests/chrome/test_retention_is_0_closes.xul
@@ -94,17 +94,17 @@ bug413093obs.prototype = {
       dm.resumeDownload(this.mDownload.id);
     }
     else if("domwindowclosed" == aTopic) {
       let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
                getService(Ci.nsIWindowWatcher);
       ww.unregisterNotification(this);
 
       // Let the UI finish doing whatever it needs to do
-      executeSoon(function() {
+      SimpleTest.executeSoon(function() {
         setPref(false);
 
         let dmui = Cc["@mozilla.org/download-manager-ui;1"].
                    getService(Ci.nsIDownloadManagerUI);
         ok(!dmui.visible, "Download Manager UI is not showing");
 
         SimpleTest.finish();
       });
--- a/toolkit/mozapps/downloads/tests/chrome/test_unkownContentType_dialog_layout.xul
+++ b/toolkit/mozapps/downloads/tests/chrome/test_unkownContentType_dialog_layout.xul
@@ -87,17 +87,17 @@ let windowObserver = {
     let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
 
     win.addEventListener("load", function onLoad(event) {
       win.removeEventListener("load", onLoad, false);
       if (win.document.documentURI != UCT_URI)
         return;
 
       // Let the dialog initialize
-      executeSoon(function() {
+      SimpleTest.executeSoon(function() {
         checkWindow(win);
         testIndex++;
         if (!tests[testIndex]) {
           ww.unregisterNotification(windowObserver);
           SimpleTest.finish();
           return;
         }
         loadNextTest();
--- a/toolkit/mozapps/downloads/tests/chrome/utils.js
+++ b/toolkit/mozapps/downloads/tests/chrome/utils.js
@@ -40,32 +40,16 @@
  * Provides utility functions for the download manager chrome tests.
  */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 
 /**
- * Executes a function shortly after the call, but lets the caller continue
- * working (or finish).
- */
-function executeSoon(aFunc)
-{
-  let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
-
-  tm.mainThread.dispatch({
-    run: function()
-    {
-      aFunc();
-    }
-  }, Ci.nsIThread.DISPATCH_NORMAL);
-}
-
-/**
  * Adds a live download to the download manager.
  *
  * @param [optional] aName
  *        The name that will be assigned to the downloaded file.
  * @returns an instance of nsIDownload.
  */
 function addDownload(aName) {
     function createURI(aObj) {