Bug 649012 - Fix some flaky mochitests which rely on non-zero timeout values; rs=ted
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 16 Apr 2011 19:39:34 -0400
changeset 68264 d8623ab1d8fd6af96ee0dd0ed2b5b91959922610
parent 68263 4a01d26c11ae44a7d88a9ce486f57ef18ae8c36f
child 68265 f1dbb031b7c5e318e5132648b5056daaf287dff9
push id19564
push usereakhgari@mozilla.com
push dateMon, 18 Apr 2011 22:53:20 +0000
treeherdermozilla-central@d8623ab1d8fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs649012
milestone6.0a1
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
Bug 649012 - Fix some flaky mochitests which rely on non-zero timeout values; rs=ted
content/html/content/test/test_bug587469.html
content/xul/document/test/test_bug583948.xul
js/src/xpconnect/tests/chrome/test_bug596580.xul
layout/base/tests/chrome/test_bug396367-1.html
layout/base/tests/chrome/test_bug396367-2.html
layout/base/tests/chrome/test_leaf_layers_partition_browser_window.xul
--- a/content/html/content/test/test_bug587469.html
+++ b/content/html/content/test/test_bug587469.html
@@ -24,16 +24,19 @@ https://bugzilla.mozilla.org/show_bug.cg
 /** Test for Bug 587469 **/
 SimpleTest.waitForExplicitFinish();
 function finish() {
   is(location.hash, "", "Should not have changed the hash.");
   SimpleTest.finish();
 }
 SimpleTest.waitForFocus(function() {
   synthesizeMouse(document.getElementsByTagName("img")[0], 50, 50, {});
-  setTimeout(finish, 50); // Sorry!
+  // Hit the event loop twice before doing the test
+  setTimeout(function() {
+    setTimeout(finish, 0);
+  }, 0);
 });
 
 
 </script>
 </pre>
 </body>
 </html>
--- a/content/xul/document/test/test_bug583948.xul
+++ b/content/xul/document/test/test_bug583948.xul
@@ -13,29 +13,29 @@
 </body>
 
 <script>
 SimpleTest.waitForExplicitFinish();
 
 var attempts = 0;
 
 function update() {
-  setTimeout(function() {
-    if (otherWindow.location)
-      otherWindow.location.reload()
-    }, 1);
-  otherWindow.document.commandDispatcher.updateCommands('');
   // without the crash fix, this usually crashes after 2 to 4 reloads
   if (++attempts == 6) {
     ok(true, "didn't crash after 6 attempts");
     otherWindow.close();
-    SimpleTest.finish();
-  }
-  else {
-    setTimeout(update, 100);
+    SimpleTest.waitForFocus(function() {
+      SimpleTest.finish();
+    });
+  } else {
+    SimpleTest.waitForFocus(function() {
+      otherWindow.location.reload()
+      SimpleTest.waitForFocus(update, otherWindow);
+    });
+    otherWindow.document.commandDispatcher.updateCommands('');
   }
 }
 
 var otherWindow = window.open("window_bug583948.xul", "_new", "chrome");
-setTimeout(update, 100);
+SimpleTest.waitForFocus(update, otherWindow);
 </script>
 
 </window>
--- a/js/src/xpconnect/tests/chrome/test_bug596580.xul
+++ b/js/src/xpconnect/tests/chrome/test_bug596580.xul
@@ -37,14 +37,14 @@
       }
     };
 
     // If the include method is defined as a global function, it works.
     // try to load a non existing file to produce the error
     Test.include("notfound.js");
 
     // If init is called directly, it works.
-    setTimeout('init();', 10);
+    setTimeout('init();', 0);
 
     SimpleTest.waitForExplicitFinish();
 
   ]]></script>
 </window>
--- a/layout/base/tests/chrome/test_bug396367-1.html
+++ b/layout/base/tests/chrome/test_bug396367-1.html
@@ -37,15 +37,15 @@ https://bugzilla.mozilla.org/show_bug.cg
 <pre id="test">
 
 <input>
 <script>document.body.setAttribute('style', 'display: -moz-box; overflow: scroll;');</script>
 <script>
 var docviewer = getdocviewer();
 docviewer.textZoom=Math.floor(10*Math.random())/4+0.2;
 document.documentElement.offsetHeight;
-setTimeout(finish,10);
+setTimeout(finish, 0);
 </script>
 
 
 </pre>
 </body>
 </html>
--- a/layout/base/tests/chrome/test_bug396367-2.html
+++ b/layout/base/tests/chrome/test_bug396367-2.html
@@ -42,17 +42,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <select></select>
 
 <li style="display: table-cell;">
 
 <script>
 var docviewer = getdocviewer();
 docviewer.textZoom=Math.floor(10*Math.random())/4+0.2;
 document.documentElement.offsetHeight;
-setTimeout(finish,10);
+setTimeout(finish, 0);
 </script>
 </li>
 </div>
 
 
 </pre>
 </body>
 </html>
--- a/layout/base/tests/chrome/test_leaf_layers_partition_browser_window.xul
+++ b/layout/base/tests/chrome/test_leaf_layers_partition_browser_window.xul
@@ -32,17 +32,17 @@
 
     function doTest(win) {
       var initialCount = win.mozPaintCount;
 
       function nextStep() {
         if (win.mozPaintCount == initialCount) {
           is(win.mozPaintCount, initialCount, "Waiting for mozPaintCount to increase.");
           // Do not use SimpleTest.executeSoon() here: give a little more time.
-          setTimeout(nextStep, 25);
+          setTimeout(nextStep, 0);
           return;
         }
 
         isnot(win.mozPaintCount, initialCount, "mozPaintCount has increased");
 
         var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                        .getInterface(Components.interfaces.nsIDOMWindowUtils);
         ok(utils.leafLayersPartitionWindow(),