Back out df780dfa7862 for xpcshell bustage on Windows and Linux
authorGregory Szorc <gps@mozilla.com>
Tue, 17 Apr 2012 16:49:40 -0700
changeset 91764 e7023f51768c
parent 91763 6700372d36d4
child 91765 b7654b9a8697
push id470
push usergszorc@mozilla.com
push date2012-04-17 23:49 +0000
Treeherderresults
milestone14.0a1
backs outdf780dfa7862
Back out df780dfa7862 for xpcshell bustage on Windows and Linux
services/common/tests/unit/test_utils_namedTimer.js
services/common/utils.js
--- a/services/common/tests/unit/test_utils_namedTimer.js
+++ b/services/common/tests/unit/test_utils_namedTimer.js
@@ -44,49 +44,26 @@ add_test(function test_delay() {
   function callback(timer) {
     // Difference should be ~2*delay, but hard to predict on all platforms,
     // particularly Windows XP.
     do_check_true((Date.now() - t0) > delay);
     run_next_test();
   }
   CommonUtils.namedTimer(callback, delay, that, "_zetimer");
   CommonUtils.namedTimer(callback, 2 * delay, that, "_zetimer");
-});
-
-add_test(function test_repeating() {
-  _("Ensure a repeating timer type works.");
-
-  const delay = 100;
-  let count = 0;
-  let that = {};
-  let t0 = Date.now();
-  function callback() {
-    count += 1;
-
-    if (count < 2) {
-      return;
-    }
-
-    let elapsed = Date.now() - t0;
-    let expectedDelay = 2 * delay;
-    do_check_true(elapsed > expectedDelay);
-
-    this._letimer.clear();
-    run_next_test();
-  }
-
-  CommonUtils.namedTimer(callback, delay, that, "_letimer",
-                         Ci.nsITimer.TYPE_REPEATING_SLACK);
+  run_next_test();
 });
 
 add_test(function test_clear() {
   _("Test clearing a timer that hasn't fired yet.");
 
   const delay = 0;
   let that = {};
   CommonUtils.namedTimer(function callback(timer) {
     do_throw("Shouldn't fire!");
   }, delay, that, "_zetimer");
 
   that._zetimer.clear();
   do_check_eq(that._zetimer, null);
   CommonUtils.nextTick(run_next_test);
+
+  run_next_test();
 });
--- a/services/common/utils.js
+++ b/services/common/utils.js
@@ -91,72 +91,46 @@ let CommonUtils = {
     }
     Services.tm.currentThread.dispatch(callback, Ci.nsIThread.DISPATCH_NORMAL);
   },
 
   /**
    * Return a timer that is scheduled to call the callback after waiting the
    * provided time or as soon as possible. The timer will be set as a property
    * of the provided object with the given timer name.
-   *
-   * @param callback
-   *        (function) Called when the timer fires.
-   * @param wait
-   *        (number) Integer milliseconds timer delay.
-   * @param thisObj
-   *        (object) Context callback is bound to during call. Timer is also
-   *        attached to this object.
-   * @param name
-   *        (string) Property in thisObj to assign created timer to.
-   * @param type
-   *        (nsITimer.TYPE_*) Type of timer to create. Defaults to
-   *        TYPE_ONE_SHOT.
    */
-  namedTimer: function namedTimer(callback, wait, thisObj, name, type) {
+  namedTimer: function namedTimer(callback, wait, thisObj, name) {
     if (!thisObj || !name) {
-      throw new Error("You must provide both an object and a property name " +
-                      "for the timer!");
-    }
-
-    // TYPE_ONE_SHOT is conveniently 0.
-    type = type || Ci.nsITimer.TYPE_ONE_SHOT;
-
-    // We rely below on TYPE_ONE_SHOT being the only timer that should be
-    // cancelled after firing. If we see a type that was not known when this
-    // was implemented, scream loudly.
-    if (type > Ci.nsITimer.TYPE_REPEATING_PRECISE) {
-      throw new Error("Unknown timer type seen: " + type);
+      throw "You must provide both an object and a property name for the timer!";
     }
 
     // Delay an existing timer if it exists
     if (name in thisObj && thisObj[name] instanceof Ci.nsITimer) {
       thisObj[name].delay = wait;
       return;
     }
 
     // Create a special timer that we can add extra properties
-    let timer = {_type: type};
+    let timer = {};
     timer.__proto__ = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
 
     // Provide an easy way to clear out the timer
-    timer.clear = function clear() {
+    timer.clear = function() {
       thisObj[name] = null;
       timer.cancel();
     };
 
     // Initialize the timer with a smart callback
     timer.initWithCallback({
       notify: function notify() {
-        // Clear out the timer once it's been triggered if it's a one shot.
-        if (timer._type == Ci.nsITimer.TYPE_ONE_SHOT) {
-          timer.clear();
-        }
+        // Clear out the timer once it's been triggered
+        timer.clear();
         callback.call(thisObj, timer);
       }
-    }, wait, type);
+    }, wait, timer.TYPE_ONE_SHOT);
 
     return thisObj[name] = timer;
   },
 
   encodeUTF8: function encodeUTF8(str) {
     try {
       str = this._utf8Converter.ConvertFromUnicode(str);
       return str + this._utf8Converter.Finish();